On Fri, Feb 27, 2009 at 11:45 AM, Øyvind Saltvik <[email protected]> wrote: > > Should be doable but you need to filter on a field of the subclass > being null. > > SomeModel.objects.filter(somemodelsubclass__somefield=None) , > somefield cannot be id or pk.
That is one method I found, but it seems very incorrect to add a field just for this, with no real data. I was wondering if it would be appropriate to add to every model subclass a "fake" field or simply to add to the query API, so that someone could do SomeModel.objects.filter(somesubclass__isinstance=True). The hypothetical name here is chosen for obvious reasons. Alternatively, something aside from filter might be appropriate, like SomeModel.objects.instancesof(SomeModelSubclass). Should I file a ticket? I would like to look at contributing an implementation of whichever would be favorable, if either would be up for consideration. > On 27 Feb, 14:13, Calvin Spealman <[email protected]> wrote: >> On Fri, Feb 27, 2009 at 1:31 AM, Malcolm Tredinnick >> >> >> >> <[email protected]> wrote: >> >> > On Thu, 2009-02-26 at 11:08 -0500, Calvin Spealman wrote: >> >> I'm looking for the best way to query based on the existence of an >> >> instance of a subclass. In my case, there are Actions that have >> >> several subclasses, like FriendRequest, PhotosTagged, etc. The user >> >> has selected a set of types they are interested in, so I need to query >> >> for all the actions that are instances of one of these particular >> >> subclasses. I could query for all, and then filter on the python-side, >> >> but that is what I'm looking to avoid. Is there a way to do this from >> >> the query api. If there isn't, what would one look like and would it >> >> be accepted? >> >> > This is a "how do I....?" sort of question. The best place to ask those >> > is the django-users mailing list. This list is for the internal >> > development of Django itself. >> >> I ask here because I've already exhausted user forums and determined >> the answer is "You can't do that", so now I'm looking for if changes >> to allow such a query would be allowed, or very easy to add. >> >> -- >> Read my blog! I depend on your acceptance of my opinion! I am >> interesting!http://techblog.ironfroggy.com/ >> Follow me if you're into that sort of thing:http://www.twitter.com/ironfroggy > > > -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
