title: Using one model to filter another model in Django
body: <p>I'm trying to access the information in my gadb_action model based on the action_ids in my gadb_vote model. I'm initially only getting the information for a particular legislator and then attempting to get the bills associated with the actions that legislator has voted on.</p>
  
  <p>Right now, my action_list is only storing action_ids, but not the related information from the gadb_action model that I want to use in my template. </p>
  
  <p>What is the best way to store that information outside of the for loop to be accessed by the template? Is there a way to write to an empty QuerySet?</p>
  
  <p>Thanks in advance for any and all help!</p>
  
  <p>view</p>
  
  <pre><code>def each_member(request,legislator_id):
      each_member = get_object_or_404(gadb_legislator, legislator_id=legislator_id)
      each_vote = gadb_vote.objects.filter(legislator_id=legislator_id)
      action_list = []
  
      for i in each_vote:
          action = gadb_action.objects.filter(action_id=i.action_id)
          action_list.append(action)
  
      context = {
          'each_member': each_member,
          'each_vote': each_vote,
          'action_list': action_list
      }
  
      return render(request, "eachmember.html", context)
  </code></pre>
  
  <p>models</p>
  
  <pre><code>class gadb_action(models.Model):
      action_id = models.IntegerField(unique=False, max_length=4, primary_key=True)
      bill_id = models.IntegerField(unique=False, max_length=12)
  
  class gadb_vote(models.Model):
      vote_id = models.IntegerField(unique=False, max_length=11,primary_key=True)
      legislator_id = models.IntegerField(unique=False, max_length=11)
      action_id = models.IntegerField(unique=False, max_length=11)
  </code></pre>
  
  <p>template</p>
  
  <pre><code>{% for i in action_list %}
      {{i.bill_id}}
      {{i.action_id}}
  {% endfor %}
  </code></pre>