Changes between Version 1 and Version 2 of Ticket #28608, comment 6
- Timestamp:
- Jan 22, 2019, 6:24:40 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28608, comment 6
v1 v2 5 5 > To work around this problem, 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. 6 6 7 However, the `UserCreationForm.save ` method initially calls the form's save method with `commit=False` but then doesn't call the `save_m2m` method within the `if commit:` block. The savemethod should be something like this so the form would behave as expected with custom user models with a many-to-many relation:7 However, the `UserCreationForm.save()` method initially calls the form's save method with `commit=False` but then doesn't call the `save_m2m` method after committing the instance if `commit=True`. The `save()` method should be something like this so the form would behave as expected with custom user models with a many-to-many relation: 8 8 9 9 {{{