title: Django model query for the closest integer match
body: <p>I got some Django model objects with different rating field values:</p>
  
  <pre><code>puzzles_rating = [0, 123, 245, 398, 412, 445, 556, 654, 875, 1000]
      for rating in puzzles_rating:
          puzzle = Puzzle(rating=rating)
          puzzle.save()
  </code></pre>
  
  <p>Now, for a <code>user_rating = 500</code>, I want to select the puzzle with the closest rating match. In the case above it should be puzzle #6 with rating 445.</p>
  
  <p>The issue is that I can't just do:</p>
  
  <pre><code>puzzle = Puzzle.objects.filter(rating__lte=user_rating).order_by('-rating')[0]
  </code></pre>
  
  <p>as, in general, my closest match rating might be greater than target rating. </p>
  
  <p>Is there a handy way to query the closest match from both directions?</p>