title: Django: Querying database with custom search algorithm
body: <p><strong>Context</strong>: I have a database of houses which users can query by location name <em>(e.g. 'New York, NY' or '100 1st Street, San Francisco')</em>. I'm using Google Maps API to retrieve pinpoints on a map of each of the query results, in addition to a list of each of the objects.
  Am using Django and Postgres as my framework and DB respectively.</p>
  
  <p><strong>Problem</strong>: I'm wondering how to filter the <code>House</code> objects by their location, but not all location queries will contain the same information (i.e. some may have a house number, some may have a city or state, and some may not). </p>
  
  <p>As shown by the code below, every <code>House</code> object is linked via a OneToOneField to a <code>Location</code> object which contains the necessary fields. </p>
  
  <p>This is also complicated by the fact that every <code>Location</code> object is made up of several fields, whereas the query will be a string that might not match a single field as you would use in Django's <code>filter()</code> method. A query such as <em>'100 1st Street, San Francisco'</em> doesn't match any of the individual <code>Location</code> fields since this query is made up of several fields. How might I write an algorithm of sorts to find any objects that match a given query as described?</p>
  
  <p><strong>Code</strong>: </p>
  
  <p>models.py:</p>
  
  <pre><code>class House(models.Model):
      ...
      mapped_location = models.OneToOneField(Location, related_name='location_house')
      ...
  
  class Location(models.Model):
      ...
      name = models.CharField(...)
      street_name = models.CharField(...)
      city = models.CharField(...)
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def show_results(request):
      House.objects.filter( ??? )
      return render(request, 'results.html', context)
  </code></pre>
  
  <p>Let me know if I need post anymore code, thanks!</p>