Opened 5 years ago

Closed 5 years ago

#28793 closed Uncategorized (invalid)

AttributeError: 'ModelName' object has no attribute 'save_m2m'

Reported by: Anjaneyulu Owned by: nobody
Component: Forms Version: 1.11
Severity: Release blocker Keywords: manytomany, modelform save, attribute error
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

instance = form.save(commit=False)
instance.updated_by = self.request.user
instance.save()
instance.save_m2m()

I'm getting below error. Django version 1.11.6

AttributeError: 'ModelName' object has no attribute 'save_m2m'

But in documentation https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/

every time you save a form using commit=False, Django adds a save_m2m() method to your ModelForm subclass. After you’ve manually saved the instance produced by the form, you can invoke save_m2m() to save the many-to-many form data.

Change History (1)

comment:1 Changed 5 years ago by Tim Graham

Resolution: invalid
Status: newclosed

You need to use form.save_m2m() rather than instance.save_m2m().

Note: See TracTickets for help on using tickets.
Back to Top