On Wednesday, July 18, 2018 at 5:16:11 AM UTC-4, Michal Petrucha wrote: > > On Tue, Jul 17, 2018 at 12:57:21PM -0700, cbpa...@gmail.com <javascript:> > 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 > > > You're right. I put a pdb trace in and that function does return an empty list. I previously had a "if not obj" in there, which was being reached, so I assumed that meant it was None, I guess that was just a misunderstanding of the "not" operator on my end.
> 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? > > If by "updating the management form" you're referring to incrementing "form-TOTAL_FORMS", then yes I'm doing that. I've tried leaving it at the default of 1 and submitting only 1 form, and I've tried incrementing it to 2 or 3 and sending more forms along with it... doesn't seem to make a difference. If there's any more information that would be helpful I'd be glad to provide it... I'm not that experienced with formsets and only used them in the admin until now, so it's possible I'm just missing something obvious. Michal -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a217be6f-b5be-43c3-b189-116920b70071%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.