Is there a way to show model fields in admin, but prevent them from
being edited? Using 'editable=False' in the model won't do, since then
the field simply is not displayed.
Also, on a related topic: is there a simple way to allow the user to
set a certain field when *creating* a new record, but then "lock" the
field from further changes? Similar to the previous question, only I
wanted to allow the field to be set when creating the record.
Thanks in advance,
Rubens
The short answer to part one is "yes," because you can customize
everything in Django. However, I don't know if it's trivial to modify
the admin in that way, and that's really not the kind of thing the
admin was intended for. You should probably just make a form for this
functionality. It would take about a minute, and the view wouldn't
take much longer.
For the second part, certainly. Just override the save function of the
model. If the object already has a primary key, then don't save those
fields. There may be a more elegant way to check whether it's already
been saved than checking the instance.id, so maybe someone else will
chime in.
Shawn
readonly_fields=('campo',)