Message from discussion
Feel free to test queryset-refactor branch
Received: by 10.35.39.1 with SMTP id r1mr3524679pyj.4.1208469241386;
Thu, 17 Apr 2008 14:54:01 -0700 (PDT)
Return-Path: <justin.fagn...@gmail.com>
Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.176])
by mx.google.com with ESMTP id x46si11030164pyg.2.2008.04.17.14.54.00;
Thu, 17 Apr 2008 14:54:01 -0700 (PDT)
Received-SPF: pass (google.com: domain of justin.fagn...@gmail.com designates 209.85.146.176 as permitted sender) client-ip=209.85.146.176;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of justin.fagn...@gmail.com designates 209.85.146.176 as permitted sender) smtp.mail=justin.fagn...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by wa-out-1112.google.com with SMTP id j32so332186waf.19
for <django-users@googlegroups.com>; Thu, 17 Apr 2008 14:54:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
bh=myBSW4xJgkuki24ZpT9bRJycH3yBPTYlpODkfQxRhLA=;
b=YWkOHFn+ClWyUz2/r+U2CNlSylkD+mb0+xyv/SfatZsTDZmI1TBU6WBnyTHp/JlqEmp1GmQyOQIN4AsDNahS5mT6ebIFH0jAaxv9FVsvfsdjF4y7rth1jPTud0wPae2WeoGCtDLXkQim7pefcYN+MMyg8nZX7jeGT95TqXYVZeQ=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
b=xfUEe2a5FNyjjzwDh9/fgOe3l/hG767uBgo1OraFACtWwz71USBFSeQn9CoeOokprvPV3PH6ruv9HI3bx+5eaipkKWuKXQ1LHt0SnNSMlsO3w/ZhVm7rXYaQ2zq65FvsNd8H+PKLjehbPiXnC9s8luWWW1vYI9BViK63ip1bPvM=
Received: by 10.115.95.1 with SMTP id x1mr2162526wal.122.1208469239909;
Thu, 17 Apr 2008 14:53:59 -0700 (PDT)
Received: by 10.114.74.9 with HTTP; Thu, 17 Apr 2008 14:53:59 -0700 (PDT)
Message-ID: <6106438e0804171453k5a923ad1u10cb3e5a6b98bacf@mail.gmail.com>
Date: Thu, 17 Apr 2008 14:53:59 -0700
From: "Justin Fagnani" <justin.fagn...@gmail.com>
To: django-users@googlegroups.com
Subject: Re: Feel free to test queryset-refactor branch
In-Reply-To: <39512ceb-b528-45f3-b799-56ee35cb2...@p25g2000hsf.googlegroups.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_4018_12123389.1208469239909"
References: <1208085814.17060.31.ca...@counterweight.tredinnick.org>
<39512ceb-b528-45f3-b799-56ee35cb2...@p25g2000hsf.googlegroups.com>
------=_Part_4018_12123389.1208469239909
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hey Malcolm,
I've been using qs-rf for a while now with basically no
problems. Excellent work.
There's one thing that may a little odd that I stumbled on while trying to
get some primitive polymorphism working:
The first thing is that there seems to be no way to tell if an instance of a
parent class has a child instance without trying the child reference and
catching the DoesNotExist exception. For a class with multiple subclasses,
this is a cumbersome, so I've been adding a _type field to parent classes
that gets set in save() of the subclasses.
Is there a better way to do this, or is this something that could be
included? I know there's no way to determine whether or not a class will be
subclassed in the future, so I wouldn't be surprised if the answer is no.
But maybe there should be a documented pattern.
The odd part is what happens with the child reference. parent.child
obviously works as expected, and returns either an instance of Child or
raises DoesNotExist. But for an instance of Child, .child always returns a
reference to itself, so that c.child == c is always True. This makes sense
on one hand, because c is also an instance of Parent, but on the other,
Child doesn't have a subclass, so should .child be None?
I haven't actually encountered this in any real life situation, because it's
hard to end up with collection in Django where you have a mix of parent and
child instances, so maybe it'll never be a problem.
One additional thing is that in one case, I know which subclasses I'm
interested in, and it'd be great to have a way to specify that a queryset
should return polymorphic results by specifying the subclasses for the join.
Something like:
Parent.objects.all().select_subclasses('Child1','Child2')
Cheers and thanks,
Justin
------=_Part_4018_12123389.1208469239909
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hey Malcolm,<div><br></div><div>I've been using qs-rf for a while now with basically no problems. Excellent work.</div><div><br></div><div>There's one thing that may a little odd that I stumbled on while trying to get some primitive polymorphism working:</div>
<div><br></div><div>The first thing is that there seems to be no way to tell if an instance of a parent class has a child instance without trying the child reference and catching the DoesNotExist exception. For a class with multiple subclasses, this is a cumbersome, so I've been adding a _type field to parent classes that gets set in save() of the subclasses.</div>
<div><br></div><div>Is there a better way to do this, or is this something that could be included? I know there's no way to determine whether or not a class will be subclassed in the future, so I wouldn't be surprised if the answer is no. But maybe there should be a documented pattern.</div>
<div><br></div><div>The odd part is what happens with the child reference. parent.child obviously works as expected, and returns either an instance of Child or raises DoesNotExist. But for an instance of Child, .child always returns a reference to itself, so that c.child == c is always True. This makes sense on one hand, because c is also an instance of Parent, but on the other, Child doesn't have a subclass, so should .child be None?</div>
<div><br></div><div>I haven't actually encountered this in any real life situation, because it's hard to end up with collection in Django where you have a mix of parent and child instances, so maybe it'll never be a problem.</div>
<div><br></div><div>One additional thing is that in one case, I know which subclasses I'm interested in, and it'd be great to have a way to specify that a queryset should return polymorphic results by specifying the subclasses for the join. Something like:</div>
<div><br></div><div>Parent.objects.all().select_subclasses('Child1','Child2')</div><div><br></div><div>Cheers and thanks,</div><div> Justin</div><div><br></div>
------=_Part_4018_12123389.1208469239909--