Changing ModelMultipleChoiceField in admin is not reflected in override save() of the same model
|Reported by:||jonathan_livni||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Consider the following:
class MyModel1 (models.Model): name = models.CharField(max_length=200) class MyModel2 (models.Model): my_model_1 = models.ManyToManyField(MyModel1, blank=True,null=True) city = models.CharField(max_length=200) def save(self, *args, **kwargs): print (",".join([mm1.name for mm1 in self.my_model_1.all()])) print (self.city) super(Filter, self).save(*args, **kwargs) print (",".join([mm1.name for mm1 in self.my_model_1.all()])) print (self.city)
Admin presents my_model_1 field as ModelMultipleChoiceField widget.
Try changing this multi-choice field in admin a few times and you'll discover the bug...
self.city prints out with the updated value, the one you entered in the admin form, both before and after the super()
but... self.my_model1 retains the previous values in the printout, both before and after the super(), although in the db it is updated after the save() completes.
btw, this is the real but and not this - my bad
Change History (7)
comment:1 Changed 6 years ago by jonathan_livni
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:5 follow-up: ↓ 6 Changed 6 years ago by russellm
- Resolution set to invalid
- Status changed from new to closed
comment:6 in reply to: ↑ 5 Changed 6 years ago by jonathan_livni
- Resolution invalid deleted
- Status changed from closed to reopened