Why can't I save my model with a generic relation twice in Django?

Posted by e-satis on Stack Overflow See other posts from Stack Overflow or by e-satis
Published on 2010-04-29T09:13:45Z Indexed on 2010/04/29 9:17 UTC
Read the original article Hit count: 318

Filed under:
|
|

I got a model TrackedItem with a generic relation linking to any model it is supposed to track.

If I do that:

t = TrackedItem(content_object=MyModel)
t.save()
t.save()

I get :

IntegrityError: (1062, "Duplicate entry '1' for key 'PRIMARY'")

Indeed, the first save has created an entry with "1" as a PK. But the second save should not insert, it should update.

How am I suppose to update a model I can't save twice?

With an ordinary model I can save as much as I want.

© Stack Overflow or respective owner

Related posts about django

Related posts about generic-relations