You need to make the
name
and category
read only once a Hero
is created. However duing the first write the fields needs to be editable.
You can do this by overriding
get_readonly_fields
method, like this:def get_readonly_fields(self, request, obj=None):
if obj:
return ["name", "category"]
else:
return []
obj
is None
during the object creation, but set to the object being edited during an edit.
No comments:
Post a Comment