title: How can I update a many to many field in Django
body: <p><strong>I am trying to update a many to many field button when a user clicks a button</strong></p>
  <p>The Payment model is to allow users to submit their receipts to be reimbursed. Each Payment has a &quot;many to many&quot; field named status. Currently, there are only two statuses a payment can have &quot;complete&quot; or &quot;incomplete&quot;. When a user submits a payment the default is incomplete, and when the company issues a check to reimburse the user, the company needs to be able to click a button that will update the payment to 'complete'.</p>
  <p>To get a better idea of what this looks like, the HTML page looks like this.
  <a href="https://i.stack.imgur.com/iJLJc.png" rel="nofollow noreferrer">The Page</a></p>
  <p><strong>My models.py</strong></p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  import uuid
  from django.urls import reverse
  
  # Create your models here.
  class Category(models.Model):
      name = models.CharField(max_length=100)
  
      def __str__(self):
          return f'{self.name}'
  
  class Status(models.Model):
      type = models.CharField(max_length=100)
  
      def __str__(self):
          return f'{self.type}'
  
  class Payment(models.Model):
      id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
      amount = models.DecimalField(max_digits=14, decimal_places=2)
      receipt_img = models.FileField(default='default.jpg', upload_to='receipt_pics')
      author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
      type = models.ManyToManyField(Category)
      time_posted = models.DateTimeField(auto_now_add=True)
      description = models.TextField(null=True)
      status = models.ManyToManyField(Status)
  
      def __str__(self):
          return f'{self.id} Contribution'
  
      def get_absolute_url(self):
          return reverse('contrib-home')
  </code></pre>
  <p><strong>The button that sends the request in payment_detail.html</strong></p>
  <pre><code>&lt;a href=&quot;{% url 'update-status' operation='complete' pk=object.id %}&quot;&gt;
      &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot;&gt;Complete&lt;/button&gt;
  &lt;/a&gt;
  </code></pre>
  <p><strong>The urls.py</strong></p>
  <pre><code>path(r'^connect/(?P&lt;operation&gt;.+)/(?P&lt;pk&gt;\d+)/$', views.update_status, name='update-status')
  </code></pre>
  <p><strong>The views.py</strong></p>
  <pre><code>class PaymentDetailView(DetailView):
      model = Payment
      template_name = 'financial/payment_detail.html'
  
  
  def update_status(request, operation, pk):
      payment = Payment.objects.get(id=pk)
      if operation == 'complete':
          print(&quot;Many to many field print&quot;)
          payment.status.first().type = 'complete'
          payment.save()
          return redirect('payment-detail', pk=pk)
      return redirect('payment-detail', pk=pk)
  </code></pre>
  <p>I have tried multiple solutions from other posts but I keep getting many errors like Cannot edit many to many fields. Any insight or help would be very helpful because there doesn't seem to be much on the internet for this.</p>