title: Django listview with multiple models and filters
body: <p>Django newbie here...</p>
  
  <p>I have three models which I'm currently wrestling with and I obtained a desired solution. However, the solution is certainly not efficient nor good practice. I just don't know enough to adequately implement what I want.</p>
  
  <p>Here are the models...</p>
  
  <p>basics/models.py</p>
  
  <pre><code>class Tag(models.Model):
      slug = models.SlugField(max_length=200, unique=True)
  
      def __unicode__(self):
          return self.slug
      def get_absolute_url(self):
          return reverse("tag_index", kwargs={"slug": self.slug})
  
  
  class post(models.Model):
      title = models.CharField(max_length = 180)
      // a bunch of other fields here
      tags = models.ManyToManyField(Tag)
  
      def get_absolute_url(self):
          return reverse("post_detail", kwargs={"slug": self.slug})
  
      def __unicode__(self):
          return self.title
  
      class Meta:
          verbose_name = "Blog Post"
          verbose_name_plural = "Blog Posts"
          ordering = ["-created"]
  </code></pre>
  
  <p>projects/models.py</p>
  
  <pre><code>class project(models.Model):
      projectTitle = models.CharField(max_length=150, null=False)
      projectTag = models.OneToOneField(Tag, primary_key=True)
      description = MarkdownField()
  
      def __unicode__(self):              # __unicode__ on Python 2
          return self.projectTitle
  
      class Meta:
          verbose_name = "Project"
          verbose_name_plural = "Projects"
  </code></pre>
  
  <p>Now... what I would like to do is to create an adequate view, which passes to my template only the posts which are tagged with the project tags rather than all posts as it is currently doing.</p>
  
  <p>projects/views.py</p>
  
  <pre><code>class projectFeed(generic.ListView):
      queryset = project.objects.all()
      template_name = "projects.html"
      paginate_by = 5
  
      def get_context_data(self, **kwargs):
          context = super(projectFeed, self).get_context_data(**kwargs)
          # slug = self.kwargs['projectTag']
          # tag = Tag.objects.get(slug=slug)
          context['posts'] = post.objects.all()#filter(tags=tag)
          return context
  </code></pre>
  
  <p>As you can see, I tried some stuff that I used for creating the view for displaying all posts with a certain tag but I couldn't get it to work here.</p>
  
  <p>projects/templates/projects.html</p>
  
  <pre><code>{% for project in project_list %}
  
  &lt;div class='postContent'&gt;
      &lt;!-- project stuff here --&gt;
  
      {% for post in posts %}
          {% if project.projectTag in post.tags.all %}
              &lt;p&gt;&lt;a href="{% url 'post_detail' slug=post.slug %}"&gt; {{ post.title }} &lt;/a&gt;&lt;/p&gt;
          {% endif %}
      {% endfor %}
  
  
  &lt;/div&gt; 
  
  {% endfor %}
  </code></pre>
  
  <p>Ideally... I want to pass a nested list of sorts where each <code>project</code> in the <code>project_list</code> has an associated list of posts which I can iterate over in the inner for loop without needing to check the tags. That is, I want to filter and arrange the data in the view method/class OR another more efficient place.</p>