title: Adding users to the specific group in Django
body: <p>I'm trying to add some users, in my Django project, to my created before group, but I know how to add to the specific group which I know the name and it's not dynamic. I would like that when I select a specific group, already add the next user. The problem is here: </p>
  
  <pre><code>g = Group.objects.get(name= 'New')
  </code></pre>
  
  <p>What should I do to replace this and indicate this group which I clicked?</p>
  
  <p>views.py:</p>
  
  <pre><code>@login_required
  def choose_group(request, pk):
  
  if request.method == "POST":
  
      cvs = get_object_or_404(Cv, pk=pk)
  
      p = Person.objects.create(name=cvs.author)
      g = Group.objects.get(name= 'New')
      m = Membership.objects.create(person=p, group=g, leader=False)
  
  
      return redirect( 'proj.views.cv_detail', pk=cvs.pk )
  
  
  
  
  
  
  
  else:
      cv = Cv.objects.filter(author = request.user)
      cvs = get_object_or_404(Cv, pk=pk)
      mem = Membership.objects.all()
  
      context = {
  
          'mem':mem,
          'cvs':cvs,
          'cv':cv
      }
  
      return render(request, 'choose_group.html', context)
  </code></pre>
  
  <p>models.py:</p>
  
  <pre><code>class Person(models.Model):
      name = models.CharField(max_length=128)
  
      def __str__(self):              # __unicode__ on Python 2
          return self.name
  
  
  class Group(models.Model):
      name = models.CharField(max_length=128)
      members = models.ManyToManyField(Person, through='Membership')
  
      def __str__(self):              # __unicode__ on Python 2
          return self.name
  
  
  class Membership(models.Model):
      person = models.ForeignKey(Person)
      leader = models.BooleanField(default=False)
      group = models.ForeignKey(Group)
  </code></pre>
  
  <p>choose_groups.html:</p>
  
  <pre><code>{% block profile %}
  
    &lt;div class="jumbotron"&gt;
      &lt;h3&gt;Choose a group to add:&lt;/h3&gt;
    &lt;/div&gt;          
  
     &lt;ul&gt;
      {% for m in mem %}
      &lt;form method="POST" class="post-form" &gt;{% csrf_token %}
        &lt;li&gt;&lt;button type="submit" class="li1"&gt; &lt;b&gt;{{ m.group }}&lt;/b&gt;&lt;/li&gt;
  
      &lt;/form&gt;
      {% endfor %}
     &lt;/ul&gt;
  
  
  {% endblock %}
  </code></pre>