dynamically adding form fields

83 views
Skip to first unread message

Matt Warren

unread,
Apr 3, 2012, 3:46:57 PM4/3/12
to django...@googlegroups.com
I'm working on a complex form and not sure if there is an elegant way to handle it in django.

The form creates an invoice and it uses jQuery to dynamically add/remove extra form fields into the HTML for line items.  Each line item contains several fields including description, unit price, quantity etc.

On the server I need to create all these line item objects and set the foreign key back to the invoice model object.  It needs to validate everything and return errors for the appropriate fields.  

I'd like to use a ModelForm or Form for the whole invoice but not sure how to represent the line item fields.

Suggestions?
Thanks

Andre Terra

unread,
Apr 3, 2012, 6:37:14 PM4/3/12
to django...@googlegroups.com

Hi Matt,

Search the docs for inlines, inline formsets and inline formset factories, and you'll find exactly what you need [0].

Read them carefully cause it's easy to make mistakes and debugging inlines has always been frustrating for me.

Good luck and happy coding.

Cheers,
AT

[0] https://docs.djangoproject.com/en/dev/topics/forms/modelforms/

On Apr 3, 201

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xaYRsc5sZxwJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages