I hope this question has not been asked yet, but I want to know if it is possible to have a normal class-based form for an object and to have an inline formset inside it to edit its related objects.
For example, I have a Contact model
class Contact(models.Model):
...
And a Communication model
class Communication(models.Model):
contact = models.ForeignKey(Contact)
and I want to have a form for Contact with a inline formset nested in it for managing communications related to it.
Is it possible to do so with existing components or do I have a hopeless dream?
EDIT : I know that the admin panel does it, but how do I make work in a view?
Of course it’s possible – how do you think the admin does it?
Take a look at the inline formsets documentation.
Edited after comment Of course, you need to instantiate and render both the parent form and the nested formset. Something like:
and the template can be as simple as:
although you’ll probably want to be a bit more detailed in how you render it.