title: How to add extra context & queryset field in Django generic views?
body: <p>I'm building Django application, with submitting links and voting functionality.</p>
  
  <p>I want to show all links, voted by a user in user details page. I can retrieve them in python shell using this:</p>
  
  <pre><code>Link.objects.filter(votes__voter=user)
  </code></pre>
  
  <p>But I don't know how to add this to the view as a extra context field. Here are the codes:</p>
  
  <p>models.py</p>
  
  <pre><code>class Link(models.Model):
      title       = models.CharField(max_length=200)
      submitter   = models.ForeignKey(User)
      submit_date = models.DateTimeField(auto_now_add=True)
      up_votes    = models.IntegerField(default=0, blank=True, db_index=True)
      ...
  
  class UserProfile(models.Model):
      user        = models.OneToOneField(User, unique=True)
      ...
  
  class Vote(models.Model):
      voter = models.ForeignKey(User)
      link = models.ForeignKey(Link, related_name='votes')
      ...
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class UserProfileDetailView(DetailView):
      model       = get_user_model()
      slug_field  = "username"
      template_name = "user_detail.html"
  
  
      def get_object(self, queryset=None):
          user    = super(UserProfileDetailView, self).get_object(queryset)s
          UserProfile.objects.get_or_create(user=user)
          return user
  </code></pre>
  
  <p>user_detail.html</p>
  
  <pre><code>...
  {% if object == request.user and request.user.is_authenticated %}
      &lt;p&gt;&lt;a href='{% url "edit_profile" %}'&gt;Edit My Profile&lt;/a&gt;&lt;/p&gt;
  {% endif %}
  
  {% if link in voted_list %}
      &lt;p&gt;&lt;a href='{% url "link_detail" %}'&gt;{{ link.title }}&lt;/a&gt;&lt;/p&gt;
  {% endif %}
  ...
  </code></pre>
  
  <p>I couldn't figure out how to implement adding extra field according to <a href="https://docs.djangoproject.com/en/1.4/topics/class-based-views/" rel="nofollow">this</a> link. I don't know that I need to define new query set, define new object or just point to a new context. If you can light this point up for me, I would be much more appreciated.</p>