summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorjpic <jamespic@gmail.com>2015-06-06 03:29:07 +0200
committerTim Graham <timograham@gmail.com>2015-07-02 13:37:30 -0400
commitfedef7b2c6e80e1e58b028cf9c03267a8950bf6f (patch)
treeb5e9e7841e422227e61bd0576172e16a46be9205 /django
parent60f795c0608119cdb02d61d3eb59f34ebdb55754 (diff)
Fixed #24908 -- Fixed duplicate readonly field rendering.
ModelAdmin added readonly_fields to exclude, but would not undeclare them if they were overridden.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/options.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 9534fad6f4..3232e8044d 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -605,7 +605,8 @@ class ModelAdmin(BaseModelAdmin):
exclude = []
else:
exclude = list(self.exclude)
- exclude.extend(self.get_readonly_fields(request, obj))
+ readonly_fields = self.get_readonly_fields(request, obj)
+ exclude.extend(readonly_fields)
if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
# Take the custom ModelForm's Meta.exclude into account only if the
# ModelAdmin doesn't define its own.
@@ -613,8 +614,16 @@ class ModelAdmin(BaseModelAdmin):
# if exclude is an empty list we pass None to be consistent with the
# default on modelform_factory
exclude = exclude or None
+
+ # Remove declared form fields which are in readonly_fields.
+ new_attrs = OrderedDict(
+ (f, None) for f in readonly_fields
+ if f in self.form.declared_fields
+ )
+ form = type(self.form.__name__, (self.form,), new_attrs)
+
defaults = {
- "form": self.form,
+ "form": form,
"fields": fields,
"exclude": exclude,
"formfield_callback": partial(self.formfield_for_dbfield, request=request),