[Django]-Django Edit Form Data: data is duplicated instead of being updated

9👍

In order to update an existing object, you have to provide that object as the instance kwarg to your form. From the docs:

>>> from django.forms import ModelForm

# Create the form class.
>>> class ArticleForm(ModelForm):
...     class Meta:
...         model = Article

# Creating a form to add an article.
>>> form = ArticleForm()

# Creating a form to change an existing article.
>>> article = Article.objects.get(pk=1)
>>> form = ArticleForm(instance=article)

0👍

You haven’t ever retrieved the original object you’re trying to update. You need to do that first!

Leave a comment