On Tue, Jul 17, 2018 at 12:57:21PM -0700,
cbpa...@gmail.com wrote:
> Is there a paid support option to get help? I've been trying to ask for
> help on IRC for a while but all I've gotten is insults.
Reading through the IRC logs, that was a pretty unpleasant exchange,
I'm sorry you were treated like that. As a community, we should do
better.
Anyway, on to your question.
> On Monday, July 16, 2018 at 6:06:00 PM UTC-4,
cbpa...@gmail.com wrote:
> >
> > I'm using Django 2.0.3 on Ubuntu 16.04. Any idea what would cause a model
> > formset to return None when calling save()? Here is the relevant code:
> >
> > RepairFormSet = modelformset_factory(Repair, form=RepairForm, exclude=[])
> >
> > form = RepairFormSet(request.POST)
> >
> > if form.is_valid():
> > form.save()
> > return render(request, 'message-loggedin', {
> > 'title': 'Success',
> > 'message': 'A repair request has been made successfully.'
> > })
> > else:
> > return render(request, 'message-loggedin', {
> > 'title': 'Error',
> > 'message': format_html(str(form.errors))
> > })
> >
> >
> > I checked the database and nothing is added to it, form.save()
> > just always returns None. When I try to debug within
> > django/forms/models.py it seems that form.has_changed() always
> > returns False, causing nothing to be saved. However I do not
> > understand why it thinks nothing has been changed. Any help would
> > be greatly appreciated.
Hmm, how do you know that form.save() returns None? Because if the
above is your literal code, then the form.save() call will definitely
return a list – the default implementation of ModelFormSet.save()
always does:
https://github.com/django/django/blob/stable/2.1.x/django/forms/models.py#L657-L669
As for why nothing is created in the database – are you also updating
the management form of the formset on the frontend to indicate that
you have added a new form, and that the formset should process it?
Michal