title: Django - Filter related objects
body: <p>Let's say I have a list of locations where each location has a list of some objects. I want to make sure that I get these locations, but with a filtered list of objects.</p>
  
  <p>Here's the structure of models.py:</p>
  
  <pre><code>class Location(models.Models):
      # fields
  
  
  class LocationObject(models.Models):
      location = models.ForeignKey(Location, related_name="objects_list")
      # other fields that are used in filtering
  </code></pre>
  
  <p>Here's how I do filtering:</p>
  
  <pre><code>locations = Location.objects.all()
  
  if request_square_from:
      locations = locations.filter(objects_list__size__gte=request_square_from)
  
  if request_square_to:
      locations = locations.filter(objects_list__size__lte=request_square_to)
  
  # Other filters ...
  </code></pre>
  
  <p>The problem is that, by using this method of filtering, I get in each location a list of objects in which there is <em>at least</em> one object that satisfies the condition in <code>locations.filter()</code>. This is not what I actually need. I need to exclude every object (I mean <code>LocationObject</code>) that doesn't satisfy the condition in the <code>filter()</code> method.</p>
  
  <p>Is there any idea to do that?</p>
  
  <p><strong>Update</strong>. A bit of clarification</p>
  
  <p>Here's how this list looks:</p>
  
  <pre><code>Location #1
     - Object 1 (size=40)
     - Object 2 (size=45)
     - Object 3 (size=30)
  
  Location #2
     - Object 4 (size=20)
     - Object 5 (size=25)
  </code></pre>
  
  <p>I want to filter each object of location by, let's say, size property. Assume this condition: <code>Location.objects.filter(objects_list__size__gte=40)</code>. This will match locations that contain even just a single list entry that has this property. This is <strong>not</strong> what I need. Expected result should be:</p>
  
  <pre><code>Location #1:
     - Object 1 (size=40)
     - Object 2 (size=45)
  </code></pre>