I was wondering how they made it possible to display more fields in the User page of the Django admin site. If you create a new User you only have some basic fields to fill in, but if you reopen that user (edit mode) then you see a lot more fields to fill in.
I'm trying to achieve the same, I had a look at the add_form.html
template but I can't really get my head around it. I guess I'm looking for a way of specifying different fields = [] sets based on the edit status of the document.
Thanks!
The answer lies in the custom admin class registered for the User model. It overrides a couple of methods on
ModelAdmin
and checks to see whether the current request is creating a newUser
(in which case the bare-bones form class for adding accounts is used) or editing an existing one (in which case a full form is shown).Here's my try. When I try to create a new item (Add) it shows only certain fields but then when I hit save it returns an error:
in /Library/Python/2.6/site-packages/django/db/models/fields/related.py in get, line 288
admin.py
forms.py