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, however I must limit > the shows based on a category type. Would slicing work for this?
Presumably you already have an ordering on the model so that "before" and "after" make sense. The difficulty in your question is working out how far to search in each direction. I can't think, for the general case, how to do it in one query. You could do it in two queries providing you can generate a queryset for "this object and everything before it" (I'm presuming you already have a queryset for "this object and everything after it). If you order the "this one and everything before it" queryset by the opposite of the default ordering, then you can slice off four items("[:4]") to get "this one and the previous four". Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---