i have two models
class A(models.Model):
name = models.CharField(50)
type = models.CharField(50)
class B(models.Model):
field1 = ForeignKeyField(A)
value = IntegerField()
I'd like to display a number of forms via a ModelFormSet (from model A) where each one of the forms displays in turn InlineFormSets (from model B) for all objects connected to the object.
How can i combine both modelformsets (model A) and inline formsets (mdoel B) on save method in django views?
I've struggled with this a week ago. I would suggest you start using the inlineformset_factory method: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
Then just add your base form and your formset to your view and render them.
Here's some blog post that helped me figure this out: http://charlesleifer.com/blog/djangos-inlineformsetfactory-and-you/
There's also a solution to make it work using Class Based Views: http://haineault.com/blog/155/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With