Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Model proxy instance does not equal the respective model instance
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Byron  
View profile  
 More options Oct 17 2010, 12:00 pm
From: Byron <bjr...@gmail.com>
Date: Sun, 17 Oct 2010 09:00:12 -0700 (PDT)
Local: Sun, Oct 17 2010 12:00 pm
Subject: Model proxy instance does not equal the respective model instance
I came across an issue when comparing a model proxy instance and a
model instance, that is:

    obj1 = Entry.objects.get(id=1)
    obj2 = EntryProxy.objects.get(id=1)

    obj1 == obj2 # False

This I feel is a bug and the culprit is in ``Model.__eq__`` where it
tests to see if the object being compared against is an instance of
the same class of the Model itself.. which will always be false for
proxy models being compared to there non-proxied instance
counterparts. It should test if it is a proxy and whether the object
is an instance of the parent class as well.

Was this a design decision or overlooked?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Byron  
View profile  
 More options Oct 19 2010, 9:08 am
From: Byron <bjr...@gmail.com>
Date: Tue, 19 Oct 2010 06:08:50 -0700 (PDT)
Local: Tues, Oct 19 2010 9:08 am
Subject: Re: Model proxy instance does not equal the respective model instance
Added ticket and patch: http://code.djangoproject.com/ticket/14492

On Oct 17, 12:00 pm, Byron <bjr...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Byron  
View profile  
 More options Oct 20 2010, 9:24 am
From: Byron <bjr...@gmail.com>
Date: Wed, 20 Oct 2010 06:24:23 -0700 (PDT)
Local: Wed, Oct 20 2010 9:24 am
Subject: Re: Model proxy instance does not equal the respective model instance
Continuing from... http://code.djangoproject.com/ticket/14492

> the real issue here is "What is a Proxy", and "what is equality"

I agree, that is the real issue. I based most of my reasoning off of
what the docs already state in that a proxy model can be written to
extend the behavior of the model being proxied, i.e. the data model
cannot be changed. That being said, I feel the default behavior when
dealing with equality, other data related things... should inherit
from there parent. If there is a need to override this behavior, I am
sure other hooks can be implemented to customize proxy models
differently then there parent. With regards to my primary issue of
equality, in this context two objects are being compared to determine
whether they represent the same row of data. It seems less likely to
compare two model objects to only be interested in whether they are
equal data structures.

Regarding permissions, the arguments presented in http://code.djangoproject.com/ticket/11154
all can be accomplished with writing a custom manager for the proxy
model or writing a custom ModelAdmin class for the admin. I agree with
Malcolm that a proxy model's permission should shadow its parent.

On Oct 19, 9:08 am, Byron <bjr...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gabriel Hurley  
View profile  
 More options Oct 20 2010, 4:21 pm
From: Gabriel Hurley <gab...@gmail.com>
Date: Wed, 20 Oct 2010 13:21:56 -0700 (PDT)
Local: Wed, Oct 20 2010 4:21 pm
Subject: Re: Model proxy instance does not equal the respective model instance
Speaking on a semantic level, a "proxy" is a stand-in acting on behalf
of (or in place of) another entity. There is an implied near-
equivalence, but inherent in the idea of a proxy is that it is *not*
the same as the original. As in the case of assigning a proxy to vote
for you in corporate elections: the proxy you delegate your right to
vote to is the functional equivalent of you, but they are recognized
as not *actually* being you.

In my mind the same reasoning applies to Proxy Models. While they are
a stand-in for accessing the same underlying data, they may have very
different properties (ordering, methods, etc.). So while they may pass
a rough equivalence test, they are in specific ways dissimilar. The
underlying table/data stored by the model is only one piece of what
makes up the sum total of a model.

That said, I can certainly see the use case for comparing proxy models
as equal to the original model...

All the best,

    - Gabriel

On Oct 20, 6:24 am, Byron <bjr...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tai Lee  
View profile  
 More options Oct 21 2010, 12:09 am
From: Tai Lee <real.hu...@mrmachine.net>
Date: Wed, 20 Oct 2010 21:09:08 -0700 (PDT)
Local: Thurs, Oct 21 2010 12:09 am
Subject: Re: Model proxy instance does not equal the respective model instance
I think that since Proxy models only affect the methods, properties
and way the data is used (not the actual underlying data itself), it
is appropriate to compare User and UserProxy as equal. To not treat
them as equal, you will need to be sure that you never pass a
UserProxy object to a 3rd party function that will attempt to compare
it to a User object. If you need to in your own code, you can always
use isinstance in combination with equality to determine how equal the
two objects are.

Cheers.
Tai.

On Oct 21, 7:21 am, Gabriel Hurley <gab...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »