Watch out for using the PK as the range like that. It's possible for
that query to return 0 records.
If show_id is 10, but records with a PK of 6-9 don't exist, and
records with a PK of 11-14 don't exist, you won't have any records
returned.
Unless, of course, that's what you want. Then carry on
> current_show = 5 #Presumably you get this in your request
> show_range = (current_show - 4, current_show + 4)
> shows = Show.objects.filter(show_order__range=show_range)
This seems to work so far.
shows = Show.objects.filter(Q(pk__range=(show_id - 4, show_id + 4) & Q
(category=category))
Behi
When you say "come before this object" and "come after this object",
how is this represented in your data model? Do you have a field called
show_order where you are capturing this information? In that case you
could do something like
current_show = 5 #Presumably you get this in your request
show_
On Wed, Feb 18, 2009 at 7:06 PM, Sean Brant wrote:
>
> Is there a simple way to say get me 4 objects from model that come
> before this object and 4 that come after this object.
>
> So lets say I have a Show. I would like to know which 4 shows come
> before the current show and which 4 come after
On Wed, 2009-02-18 at 16:06 -0800, Sean Brant wrote:
> Is there a simple way to say get me 4 objects from model that come
> before this object and 4 that come after this object.
>
> So lets say I have a Show. I would like to know which 4 shows come
> before the current show and which 4 come after
Is there a simple way to say get me 4 objects from model that come
before this object and 4 that come after this object.
So lets say I have a Show. I would like to know which 4 shows come
before the current show and which 4 come after, however I must limit
the shows based on a category type. Woul
6 matches
Mail list logo