#20352: ModelAdmin form validation does not check inherited
get_readonly_fields()
-------------------------------------+-------------------------------------
Reporter: soulne4ny | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.5
Severity: Normal | Resolution: invalid
Keywords: admin readonly | Triage Stage:
fields validation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by DrMeers):
* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
The minimal sample project is appreciated, thank you. There were a few
errors within it, but having remedied them I think I've reproduced your
issue.
According to the
[https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fields
/ docs] "The fields option, unlike list_display, may only contain names of
fields on the model or the form specified by form. It may contain
callables only if they are listed in readonly_fields."
So technically your use of `'a_field'` in `fields` here is invalid if it
is only returned by `get_readonly_fields` rather than defined in
`readonly_fields`. Unlike your example, `get_readonly_fields` takes a
request and optional model instance as arguments, which cannot be done by
the validation code as it is not request-specific.
I believe your example works when you override the `get_form` method via
the mixin because the super call to `get_form` bypasses the `fields` value
specified at the `MixIn` level.
--
Ticket URL: <https://code.djangoproject.com/ticket/20352#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.