Jeremy Dunck wrote:
> On 5/18/07, Olivier Guilyardi <[EMAIL PROTECTED]> wrote:
> ...
>> Okay, so I suppose a workaround is to pass offset and length as arguments to
>> my_query()
>>
> ...
>> I suppose I may also try to extend the QuerySet class to add my own method. 
>> But
>> this might get rather complex AFAICS in db.models.query.
> 
> If you give a better idea of what you're trying to accomplish, there
> may be an easier way.
> 
> Have a look at db.query.Q, for example, which can be used to build
> queries in a flexible way, for example:
> http://www.djangoproject.com/documentation/db-api/#complex-lookups-with-q-objects

I'm already using Q for other purposes, but I'm afraid it won't help here.

Here's what I want to run custom SQL for: I have collections and items, many
items relate to one collection. Each item comes from a given country. In the
item table there's a country field, but there is no such field in the collection
table. One collection may contain items that come from several countries.

I want to display all collections that contain items which come from a given
country, say Guatemala. There's much data, so I need to paginate through those
displayed collections after they've been ordered by title.

In SQL I would do:

SELECT DISTINCT collection.* FROM collection INNER JOIN item
ON collection.id = item.collection_id
WHERE item.country = 'Guatemala'
ORDER BY collection.title
LIMIT 0, 20;

--
  Olivier

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to