#13618: prepopulated_fields crashes with get_readonly_fields
------------------------------------------------+---------------------------
Reporter: tonnzor | Owner: tobias
Status: assigned | Milestone: 1.3
Component: django.contrib.admin | Version: SVN
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 1 |
------------------------------------------------+---------------------------
Comment (by anonymous):
Replying to [comment:11 russellm]:
> 1) Raise a validation error, prohibiting the use of a prepopulated
value in a readonly.
That already raises Exception when prepopulated and readonly are used
together on the same field.
I have a strong usecase that is really demanded and I hoped that these
changes would cover it. If you have a better idea how to handle it - it
would be great.
Usecase: There's an object that has a slug. However, that slug field that
shouldn't be changeable after an object becomes published (at it would
break all the links). For that purpose I use static `prepopulated_fields`
definition and generate `readonly_fields` on-fly (for needed items) by
`get_readonly_fields`. Of course if I may generate `prepopulated_fields`
on-fly with some method (like `def get_prepopulated_fields(self, request,
obj=None)`) - I would simply remove that slug field from it to not
conflict with `readonly_fields`.
In that usecase that is excellent that user cannot change or define slug
field. If user didn't define it before - that would raise validation
errors on previous save. Yes, developer may implement
`get_readonly_fields` incorrectly - like slug field is not editable on
object creation - then user wouldn't be able to save that object (as empty
slug will generate validation error too). We cannot guarantee that this
feature is used properly, but developer will face that issue from the very
beginning.
In my point of view, field representation should not influence to
`readonly_fields` property - it should be not allowed for editing (shown
as plain text) in any case. Then how field look/work like (e.g. being
prepopulated) should not make difference. Readonly works for all the
fields and should work for prepopulated field too.
--
Ticket URL: <http://code.djangoproject.com/ticket/13618#comment:12>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.