diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/options.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 0804697594..499d27d02e 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -282,6 +282,12 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): except AttributeError: return mark_safe(self.admin_site.empty_value_display) + def get_exclude(self, request, obj=None): + """ + Hook for specifying exclude. + """ + return self.exclude + def get_fields(self, request, obj=None): """ Hook for specifying fields. @@ -605,13 +611,11 @@ class ModelAdmin(BaseModelAdmin): fields = kwargs.pop('fields') else: fields = flatten_fieldsets(self.get_fieldsets(request, obj)) - if self.exclude is None: - exclude = [] - else: - exclude = list(self.exclude) + excluded = self.get_exclude(request, obj) + exclude = [] if excluded is None else list(excluded) 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: + if excluded 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. exclude.extend(self.form._meta.exclude) @@ -1851,12 +1855,10 @@ class InlineModelAdmin(BaseModelAdmin): fields = kwargs.pop('fields') else: fields = flatten_fieldsets(self.get_fieldsets(request, obj)) - if self.exclude is None: - exclude = [] - else: - exclude = list(self.exclude) + excluded = self.get_exclude(request, obj) + exclude = [] if excluded is None else list(excluded) exclude.extend(self.get_readonly_fields(request, obj)) - if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude: + if excluded is None and hasattr(self.form, '_meta') and self.form._meta.exclude: # Take the custom ModelForm's Meta.exclude into account only if the # InlineModelAdmin doesn't define its own. exclude.extend(self.form._meta.exclude) |
