UpdateView for Editing Objects
Update records with UpdateView and form handling.
# models.py
from django.db import models
class Profile(models.Model):
username = models.SlugField(unique=True)
bio = models.TextField(blank=True)
# admin.py
from django.contrib import admin
from .models import Profile
@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ("username",)
# views.py
from django.views.generic import UpdateView
from django.urls import reverse_lazy
from .models import Profile
class ProfileUpdate(UpdateView):
model = Profile
fields = ["bio"]
slug_field = "username"
slug_url_kwarg = "username"
template_name = "profiles/form.html"
success_url = reverse_lazy("profile-list")
# urls.py
path("profiles//edit/", ProfileUpdate.as_view(), name="profile-update")
Explanation:
- UpdateView reuses the same template pattern as CreateView.
- Limit editable fields to prevent mass-assignment issues.
- Category Views (FBV & CBV)
- Total Views 1160
- Last Modified 06 December, 2025
- Tags #cbv #updateview #forms #edit
Previous snippet
CreateView with ModelForm
Next snippet