On 3/7/06, Alan Bailey <[EMAIL PROTECTED]> wrote:

Hi there -

I'll just start into the example I'm wondering about without introducing
it.  We have a bunch of users, along with the 'resources' they have access
to.

So, I can do this:

me = persons.get_object (username__exact='bailey')
me.get_resourcerecord(resource=resourcetypes.get_object(short_name__exact='clusterA'))

except I want to do this for the last line:

me.get_resourcerecord('clusterA')

Is this possible?  Obviously the first example hits the database twice
unideally.  This should be possible to do, it's not hard to put into the
framework.

It's a little difficult to understand exactly what it is you want without a concrete model example - but if I'm understanding you correctly, the answer is 'it may be possible with trunk/0.91, and is definitely possible with magic-removal'.

When you construct a query argument (short_name__exact), you use a double _ to separate the column name from the query condition. You can also use a double _ to perform lookups over joins - so, resourcetypes__short_name__exact will do the join across resource types in a query on resource records.

However, trunk/0.91 has a few restrictions on this - queries can only follow in the direction that fields are defined in your model. i.e., if Person defines a m2m field on ResourceRecord, you can query persons.get_list (resourcerecord__ ...), but not resourcerecords.get_list(person__...)

This limitation has been fixed in the magic-removal development stream. Keeping in mind that magic-removal query syntax is a little different to what you are used to, the query will look something like:

me.resourcerecord.filter(resourcetypes__short_name__exact='clusterA')

Hope this helps,

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to