title: Django: Get the next and previous item IDs for a specific item given multiple OR parameters
body: <p>I've got a basic Item model in my Django app:</p>
  
  <pre><code>class Item(models.Model):
      name = models.CharField(max_length=200)
      brand = models.ForeignKey(User, related_name='items')
      price = models.CharField(max_length=10)
      upload_date = models.DateTimeField(auto_now=False, auto_now_add=True)
  </code></pre>
  
  <p>For a given item, I am trying to get the next and previous items in the db. </p>
  
  <p>I know I can do this using Django's built-in <code>Model.get_next_by_FOO(**kwargs)</code>, which works perfectly well with the <code>upload_date</code> field, but I need to get the previous and next items given certain OR parameters (for example items that have a certain brand OR are under a certain price).</p>
  
  <p>I can get the previous item using a query like this:</p>
  
  <pre><code>previous_item = Item.objects.filter(id__lt=item.id).filter(Q(brand__in=brands)|Q(price__lt=100))[:1]
  </code></pre>
  
  <p>My problem is with the next item. Running the same query for the next item results in the most recent item overall that meets the criteria, not the item that comes after the current item in the database. I understand that this is because of the way Django queries the database, but don't know how to get around it to get the item that comes directly after the current item that also meets the criteria.</p>
  
  <p>Is there a fast, simple way to get the next item for a specific item given multiple OR parameters?</p>
  
  <p>Thanks!</p>