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
Getting the original object from a proxy in Python
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
  3 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
 
Paul Walsh  
View profile  
 More options Oct 31 2012, 4:29 am
From: Paul Walsh <paulywa...@gmail.com>
Date: Wed, 31 Oct 2012 01:29:50 -0700 (PDT)
Local: Wed, Oct 31 2012 4:29 am
Subject: Getting the original object from a proxy in Python

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.

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, but my
proxies, in this case, are on Django's User object.


 
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.
Shai Berger  
View profile  
 More options Oct 31 2012, 7:19 am
From: Shai Berger <s...@platonix.com>
Date: Wed, 31 Oct 2012 13:19:29 +0200
Local: Wed, Oct 31 2012 7:19 am
Subject: Re: [pyweb-il:3717] Getting the original object from a proxy in Python
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.


 
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.
Paul Walsh  
View profile  
 More options Oct 31 2012, 9:18 am
From: Paul Walsh <paulywa...@gmail.com>
Date: Wed, 31 Oct 2012 06:18:00 -0700 (PDT)
Subject: Re: [pyweb-il:3717] Getting the original object from a proxy in Python

ok yes, I am using the pk now, so I guess this is the way to do it. thanks.


 
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 »