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!
- [Django]-MySQL Query error when run within Python but not when run directly
- [Django]-Csrf_token cookie deleted by another site?
- [Django]-Django – CSS File Not Loading In Production (Debug: False)
Source:stackexchange.com