Q:

Can't update the model instance in Django?

I am trying to make a Q/A website in Django and I have trouble in the creating the question's update view for the app. 
Here is the QuestionUpdateView class 
class QuestionUpdateView(UpdateView):
    model = models.Question
    form_class = forms.QuestionForm
    template_name = 'Questionnaire/form.html'
    success_url = 'question:details'

    def get_success_url(self, **kwargs):
        return redirect(self.success_url, self.kwargs['slug'])

    def post(self, request, *args, **kwargs):
        filled_form = self.form_class(request.POST)
        if self.form_class.is_valid(filled_form):
            model = filled_form.save(commit=False)
            model.clean()
            model.save()
            return self.get_success_url(slug=model.slug)

And here is the Question model
class Question(models.Model):
    title = models.CharField(max_length=250)
    body = models.TextField()
    asked_by = models.ForeignKey(User)
    pub_date = models.DateTimeField(auto_now_add=timezone.now)
    slug = models.SlugField(max_length=250, unique=True, default=None)
    likes = models.PositiveIntegerField(editable=False, default=0)
    dislikes = models.PositiveIntegerField(editable=False, default=0)

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        if self.slug is None:
            self.slug = slugify(self.title)+'-'+str(self.id)
        super(Question, self).save(force_insert, force_update, using, update_fields)

    def get_absolute_url(self):
        return reverse('question:details', kwargs={'slug': self.slug})

    def __str__(self):
        return self.title

What is the problem with the code? Whenever i update the question it create's a new instance instead of saving the one got from the form class.

A:

You can use form_valid instead of post and get a lot of the checks you've tried to do there for free, and model.clean() is called as part of the form validation process.
def form_valid(form):
    form.save()
    return self.get_success_url(slug=model.slug)

You may also do better letting the parent class handle the default arguements for save
def save(self, *args, **kwargs):
    if self.slug is None:
        self.slug = slugify(self.title)+'-'+str(self.id)
    super(Question, self).save(*args, **kwargs)

It could be that your update_fields=None could be preventing the save, see Django Model instance reference
EDIT as per the comment, you should be returning a URL. Use reverse() rather than redirect django.urls utility functions

