title: Django filter foreignkey field
body: <p><strong>Short version:</strong></p>
  
  <p>I have a Django app used for recipes, and want to filter data to be sent to a template in my view. I basically want all recepies that are added by a specific user to be sent as context. The following filtering returns an error message <strong>invalid literal for int() with base 10: <em>my_username</em></strong>.</p>
  
  <pre><code>recipes = Recipe.objects.filter(added_by = uname)
  </code></pre>
  
  <p>The variable <em>uname</em> is passed from a template. On the other hand, filtering on <em>request.user</em> works fine, but is not what I want.</p>
  
  <pre><code>recipes = Recipe.objects.filter(added_by = request.user)
  </code></pre>
  
  <p><strong>Details:</strong></p>
  
  <p>My models are given (relevant fields) as:</p>
  
  <pre><code>class Recipe (models.Model):
      ...
      ...
      added_by = models.ForeignKey(User)
  </code></pre>
  
  <p>Where <em>User</em> is an existing Django user. When I call {{ recipe.added_by }} in my template, I get the username as wanted. This username is passed on to a view with <em>href="/profile/{{recipe.added_by}}"</em>, where the view looks like the following:</p>
  
  <pre><code>def profile(request, uname):
  
      print uname #Correct username printed
      print request.user #Logged in user (not relevant, as userprofile should be visible for all)
  
      recipes = Recipe.objects.filter(added_by = uname) #Does not work. Why?
      #recipes = Recipe.objects.filter(added_by = request.user)
  
      form = CommentForm(request.POST)
  
      context = {
          'uname': uname,
          'recipes': recipes,
          'form': form,
      }
      return render(request, '*app_name*/profile.html', context)
  </code></pre>
  
  <p>Not sure what I am missing, but from what I can tell, it seems to have something to do with the fact that <em>added_by</em> has a Foreign Key to a User. I also tried to change the filter argument to <em>recipe__added_by__added_by = uname</em> according to [1], but Django then returned an error saying "Cannot resolve keyword 'recipe' into field", which seems obvious. My url is:</p>
  
  <pre><code>url(r'^profile/([a-zA-Z0-9]+)/$', 'profile', name='*app_name*-profile'),
  </code></pre>
  
  <p>Thanks for any reply. Sorry if this should have been obvious. </p>
  
  <p>[1] <a href="https://stackoverflow.com/questions/11508744/django-models-filter-by-foreignkey">Django models filter by foreignkey</a></p>