On Wednesday 31 October 2012 10:29:50 Paul Walsh wrote:
> In a new project I am working with Django's proxy models, and it is just a
> great great way to build pragmatic interfaces for views and templates.
>
> In a few cases, however, I need to do things like check equality with the
> original object, and my proxy is not actually equal to the original of
> course.
>
> I can do this by checking equality on class properties, where that property
> is the same in the proxy and the original object.
>
With Django objects you can usually rely on the pk property (except if your
context involves unsaved objects).
> I wonder if there is a better practice in python. I found some suggestions
> to add a method on the original object that simply returns self
That, simply, won't work -- such a method will return the dynamic self (the
proxy), not an instance of the class in which it was defined (as might be the
case in some static languages).
HTH,
Shai.