title: Django views.py: Add to favorites page
body: <p>I am trying to edit an html page so a logged in user can favorite a <code>video.id</code></p>
  
  <p>Here is the <strong>.html</strong> file</p>
  
  <pre><code>&lt;td&gt;
      &lt;form method='POST' action="{% url 'foobar:favourite_post' video.id %}"&gt;
          {% csrf_token %}
          &lt;input type='hidden' name='video' value={{ video.id }}&gt;
          &lt;button type='submit'&gt;Bookmark&lt;/button&gt;
      &lt;/form&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>Here is the <strong>urls.py</strong> file</p>
  
  <pre><code>app_name = 'foobar'
  
  urlpatterns = [
      path('', views.f_ListView.as_view(), name='overview'),
      path('&lt;int:pk&gt;/', views.f_DetailView.as_view(), name='detailview'),
      path('&lt;int:fav_id&gt;/favourite_post/', views.favourite_post, name='favourite_post'),
  ]
  </code></pre>
  
  <p>Here is the <strong>view.py</strong> file </p>
  
  <pre><code>def favourite_post(request, fav_id):
      video = get_object_or_404(Video, id=fav_id)
      if request.method == 'POST': #Then add this video to users' favourite
          video.
  
     return render(request, 'foobar/%s' % fav_id)
  </code></pre>
  
  <p>How to edit the <strong>views.py</strong> file so it is registered in the database that the user has favorited this video ? </p>
  
  <p>Here is the <strong>models.py</strong> file</p>
  
  <pre><code>from django.contrib.auth.models import AbstractUser
  
  class ProjectUser(AbstractUser):
  
      def __str__(self):
          return self.email
  
  class Video(models.Model):
      name = models.CharField(max_length=255),
      videofile = models.FileField(upload_to="static/videos/"),
      favourite = models.ManyToManyField(ProjectUser, related_name="fav_videos", blank=True)
  </code></pre>