django inline formsets with a complex model for the nested form

前端 未结 3 732
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 16:36

Say I have django model that looks something like this:

class Order(models.Model):
 number = models...
 date = models...

class OrderLine(models.Model):
 # O         


        
3条回答
  •  执笔经年
    2020-12-18 17:08

    I solved problem with http://yergler.net/blog/2009/09/27/nested-formsets-with-django/. Pleas use the following correction in forms.py file:

            instance=None
                pk_value = hash(form.prefix)
    
    +       correct_data = None
    +       if (self.data):
    +           correct_data = self.data;
            # store the formset in the .nested property
            form.nested = [
    -           TenantFormset(data=self.data,
    +           TenantFormset(data=correct_data,
                                instance = instance,
    

    Just working on Django 1.4.1 very well.

提交回复
热议问题