[Django] #28793: AttributeError: 'ModelName' object has no attribute 'save_m2m'

7 views
Skip to first unread message

Django

unread,
Nov 12, 2017, 1:09:27 PM11/12/17
to django-...@googlegroups.com
#28793: AttributeError: 'ModelName' object has no attribute 'save_m2m'
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Anjaneyulu |
Type: | Status: new
Uncategorized |
Component: Forms | Version: 1.11
Severity: Release | Keywords: manytomany,
blocker | modelform save, attribute error
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28793>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 12, 2017, 1:14:29 PM11/12/17
to django-...@googlegroups.com
#28793: AttributeError: 'ModelName' object has no attribute 'save_m2m'
-------------------------------------+-------------------------------------
Reporter: Anjaneyulu | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 1.11
Severity: Release blocker | Resolution: invalid
Keywords: manytomany, | Triage Stage:
modelform save, attribute error | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28793#comment:1>

Reply all
Reply to author
Forward
0 new messages