I'm using `ModelAdmin.save_model` to set some data from the `request` object to my instance.
When I change an existing `Magasin` instance from the admin, I get an `IntegrityError`, eg: "Duplicate entry '220' for key 'PRIMARY'" meaning that in Model.save, the instance is created, instead of being updated. When I do it programmatically, it works as expected, and the instance is updated: m = Magasin() m.nom="test" m.region_id=3 m.save() m.nom="test_modified" m.save() # no error What's wrong? Anybody can help? *models.py* class Magasin(models.Model): nom = models.CharField(max_length=200) region = models.ForeignKey(Region, blank=True, null=True) def save(self, *args, **kwargs): if self.region_id is None: self.region_id = args[0] super(Magasin, self).save(*args, **kwargs) *admin.py* class MagasinAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): # more stuff obj.save() -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/J8F6eKMuUBwJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.