Related Field got invalid lookup: icontains
<p>I am trying to include a search field inside my home page. It works for some of the module field. My problem is when I use a ForeignKey field (correct me please if I am wrong).</p>

<p><strong>models.py</strong></p>

<pre><code>class Location(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    my_location = models.CharField(max_length=120, choices=LOCATION_CHOICES)
    update_date = models.DateField(auto_now=True, null=True)

    def __str__(self):
        return self.my_location


class UserProfile(models.Model):

    user = models.ForeignKey(User)
    # The additional attributes we wish to include.
    user_base = models.CharField(max_length=120, choices=LOCATION_CHOICES)
    user_position = models.CharField(max_length=120)
    user_phone = models.PositiveIntegerField()

    def __unicode__(self):
        return self.user.username
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>def search_by_location(request):
    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']
        locations = Location.objects.filter(my_location__icontains=q).order_by('-update_date')
    else:
        locations = Location.objects.order_by('-update_date')
context = {'locations': locations}
return render(request, 'index.html', context)
</code></pre>

<p>My problem is if I use <code>user</code> inside the filter query instead of <code>my_location</code> I receive the error:</p>

<blockquote>
  <p>Related Field got invalid lookup: icontains</p>
</blockquote>

<p>Please any advice on how to troubleshoot or any documentation I can read.</p>