I was writing some unit tests for a model in which I'd written a custom
__cmp__ method and got a strange result. Is it a bug, feature, or just
something to warn people about.

django.db.models.Model defines __eq__ and __ne__ based on  PK identity.
That means that all model objects are == to one another until they've
been saved in the database because their PKs don't get set until they're
saved.

In my case,

>>> name1 < name2 and name2 > name1
True
>>> name1 != name2
False

Is it worth it to check if the PK exists in the equality check, or have
I just hit something that's not likely to ever surface in the real
world?

Todd


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to