title: ManyToMany Relationship between two models in Django
body: <p>I am trying to build a website that users can add the courses they are taking. I want to know how should  I add the ManyToMany relationship. Such that we can get all users in a course based on the course code or instructor or any field. And we can also get the courses user is enrolled in. Currently, my Database structure is: </p>
  
  <pre><code>class Course(models.Model):
      course_code = models.CharField(max_length=20)
      course_university = models.CharField(max_length=100)
      course_instructor = models.CharField(max_length=100)
      course_year = models.IntegerField(('year'), validators=[MinValueValidator(1984), max_value_current_year])
  
      def __str__(self):
          return self.course_code
  </code></pre>
  
  <p>and my user model:</p>
  
  <pre><code>class Profile(AbstractUser):
      bio = models.TextField()
      image = models.ImageField(default='defaults/user/default_u_i.png', 
      courses = models.ManyToManyField('home.Course',related_name='courses')
  
      def __str__(self):
          return self.username
  </code></pre>
  
  <p>I was wondering should ManyToMany relationship be in User model or the course model? Or will it make any difference at all?</p>
  
  <p><strong>EDIT</strong>: For adding course to post object now I am using this view but it seems to not work: </p>
  
  <pre><code>@login_required
  def course_add(request):
  
      if request.method == "POST":
          form = CourseForm(request.POST or none)
          if form.is_valid():
              course = form.save()
              request.user.add(course)
      else:
          form = CourseForm
      context = {
          'form':form
      }
      return render(request,'home/courses/course_add.html', context)
  </code></pre>