0👍
I was able to get the inline model formset working as per Daniel’s suggestion with help from this blog post: http://charlesleifer.com/blog/djangos-inlineformsetfactory-and-you/
Just as an FYI, one crucial point I was missing is that the formset’s instance refers to the parent model. Also, if you’re displaying the formset manually in your template, don’t forget to include {{ formset.id }}.
1👍
For some strange reason, you’re correctly passing instance
to the main forms, but initial
to EventScheduleModelFormSet, which is the immediate cause of the problem.
However, since these models obviously have a foreign key relationship, it sounds like you should be using a inline model formset:
from django.forms.models import inlineformset_factory
eventschedule_formset_class = inlineformset_factory(Event, EventSchedule)
event_sched_formset = eventschedule_formset_class(request.POST or None,
instance=event_to_edit)
Now there is no need for that updateEvent
logic – you can just save event_sched_formset
and it will correctly reference the event.
- [Answer]-\distutils\dist.py:267: UserWarning: Unknown distribution option: 'use_2to3'
- [Answer]-Passing a kwargs parameter to a ModelForm Field constructor?
- [Answer]-Django call custom middleware only when user is logged in
- [Answer]-Python manage.py dbshell doesn't find psycopg2 although it is installed and in path
0👍
you are trying to save the EventScheduleModelFormSet form? there is no instance set only initial data so you are creating a new object every time. or am I missing something?
- [Answer]-How to reverse link foreign key in Django model?
- [Answer]-Django throwing error with '/' in url
- [Answer]-Django object has no attribute 'all'