diff options
| author | Zach Borboa <zachborboa@gmail.com> | 2016-09-29 02:55:10 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-10-07 18:49:28 -0400 |
| commit | bf91be83d56d70181de807a5e8d22679cf63a52f (patch) | |
| tree | c12c401aa3cbe6b4bd9fd58d97af4bdc20f3bf94 /django | |
| parent | c60feb6999f83bfd1fdabff01f0dd4a26d72e158 (diff) | |
Fixed #24941 -- Added ModelAdmin.get_exclude().
Thanks Ola Sitarska for the initial patch.
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) |
