views.generic.edit.UpdateView.object

object

When using UpdateView you have access to self.object, which is the object being updated.

Example myapp/views.py:

1
2
3
4
5
6
7
from django.views.generic.edit import UpdateView
from myapp.models import Author
 
class AuthorUpdate(UpdateView):
    model = Author
    fields = ['name']
    template_name_suffix = '_update_form'

Example myapp/author_update_form.html:

1
2
3
4
<form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Update" />
</form>
doc_Django
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.