diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 733f89d06f0..a02bb7a316f 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -6,7 +6,7 @@ from django.forms.models import (BaseModelForm, BaseModelFormSet, fields_for_mod from django.contrib.admin import ListFilter, FieldListFilter from django.contrib.admin.util import get_fields_from_path, NotRelationField from django.contrib.admin.options import (flatten_fieldsets, BaseModelAdmin, - HORIZONTAL, VERTICAL) + ModelAdmin, HORIZONTAL, VERTICAL) __all__ = ['validate'] @@ -388,12 +388,14 @@ def check_formfield(cls, model, opts, label, field): raise ImproperlyConfigured("'%s.%s' refers to field '%s' that " "is missing from the form." % (cls.__name__, label, field)) else: - fields = fields_for_model(model) - try: - fields[field] - except KeyError: - raise ImproperlyConfigured("'%s.%s' refers to field '%s' that " - "is missing from the form." % (cls.__name__, label, field)) + get_form_is_overridden = hasattr(cls, 'get_form') and cls.get_form != ModelAdmin.get_form + if not get_form_is_overridden: + fields = fields_for_model(model) + try: + fields[field] + except KeyError: + raise ImproperlyConfigured("'%s.%s' refers to field '%s' that " + "is missing from the form." % (cls.__name__, label, field)) def fetch_attr(cls, model, opts, label, field): try: diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 1414f19e488..3c051301619 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -1096,6 +1096,13 @@ templates used by the :class:`ModelAdmin` views: changelist that will be linked to the change view, as described in the :attr:`ModelAdmin.list_display_links` section. +.. method:: ModelAdmin.get_fieldsets(self, request, obj=None) + + The ``get_fieldsets`` method is given the ``HttpRequest`` and the ``obj`` + being edited (or ``None`` on an add form) and is expected to return a list + of two-tuples, in which each two-tuple represents a ``