Why can't I save my shared relation model twice in Django?
I have a TrackedItem model with a generic relationship associated with whatever model it needs to track.
If I do this:
t = TrackedItem(content_object=MyModel) t.save() t.save()
I get:
IntegrityError: (1062, "Duplicate entry '1' for key 'PRIMARY'")
Indeed, the first save created an entry with "1" as a PC. But the second save shouldn't be inserted, it should be updated.
How do I go about updating a model that I cannot save twice?
With a regular model, I can save as much as I want.
EDIT: It may have nothing to do with generic relations at all.
I have an overridden save and I call super in it like this:
super(TrackedItem, self).save(self, *args, **kwargs)
if i do this it works:
model.Model.save(self, *args, **kwargs)
+2
a source to share