title: How to update a django moodel value from a button click in a class based view
body: <p>i currently have a model that looks like:</p>
  <p><strong>Model</strong></p>
  <pre><code>class Answer(models.Model):
      question = models.ForeignKey(Question, on_delete=models.CASCADE, related_name='answers')
      author = models.ForeignKey(User, on_delete=models.CASCADE)
      content = models.TextField()
      date_posted = models.DateTimeField(default=timezone.now)
      is_best_answer = models.BooleanField(default=False)
  
      def set_best_answer(self):
          self.is_best_answer = True
          self.save()
  
      def get_absolute_url(self):
          return reverse('question-detail', kwargs={'pk': self.question.pk})
  
      def __str__(self):
          return f&quot;Answer by {self.author} with text: {self.content}&quot;
  </code></pre>
  <p>I have a Class based Listview which lists all of the answers above. I want to add a button in the template that would update the value in the model of is_best_answer to True e.g.</p>
  <p><strong>html</strong></p>
  <p><code>&lt;a class=&quot;btn btn-outline-dark &quot; href=&quot;{% url 'select' answer.id %}&quot;&gt;Set Best Answer&lt;/a&gt;</code></p>
  <p><strong>view</strong></p>
  <pre><code>def set_best_(request, pk):
      answer = Answer.objects.filter(pk=pk).first()
      answer.set_best_answer()
  
      return redirect('/')
  </code></pre>
  <p><strong>url</strong></p>
  <pre><code>path('answer/&lt;int:pk&gt;/best-answer/',  set_best, name='select'),
  </code></pre>
  <p>The above works for me, but i have had to call a function rather than anything to do with the class based views. Is there a better way?</p>
  <p>Dango version 3.1</p>