Hi, I'd like to understand how to manage newforms save when coping with a form that should edit both heading info and details. As an example let's think at an invoice splitted between invoice_headings/invoice_detail in a way similar to the following:
class InvoiceHeading(Model): company = CharField(max_length=10) date = DateField() ... class InvoiceDetail(Model): invoice = ForeignKey(InvoiceHeading) qty = integerField() description = CharField(max_length=50) Let suppouse that we are only interested in a form that allows us to edit 3 invoice rows. A form could resamble this one: class InvoiceForm(form_for_model()): def __init__(self): opts = {'required' : False} for row in range(3): self.fields['row_%s_qty' % (row)] = IntegerField(**opts) self.fields['row_%s_descr' % (row)] = CharField(maxlength=50, **opts) Now how should I define save()? I tried something similar: def save(self): self.invoice = super(InvoiceForm, self).save() for row in range(3): InvoiceDetail(qty=self.clean_data['row_%s_qty' % row], description=self.clean_data['row_%s_descr' %row],).save() This works when I create an object but how should I define it to make it able to update the object. This would just insert new rows each time. Should I use get_or_create? Is there a sample code for this kind of compound form? Thanks in advance *:-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---