diff --git a/django/core/meta.py b/django/core/meta.py index 189114219db..5c8d070f407 100644 --- a/django/core/meta.py +++ b/django/core/meta.py @@ -2136,7 +2136,7 @@ class OneToOne(ManyToOne): self.raw_id_admin = raw_id_admin class Admin: - def __init__(self, fields, js=None, list_display=None, list_filter=None, date_hierarchy=None, + def __init__(self, fields=None, js=None, list_display=None, list_filter=None, date_hierarchy=None, save_as=False, ordering=None, search_fields=None, save_on_top=False): self.fields = fields self.js = js or [] @@ -2148,10 +2148,17 @@ class Admin: self.save_on_top = save_on_top def get_field_objs(self, opts): - # Returns self.fields, except with fields as Field objects instead of - # field names. + """ + Returns self.fields, except with fields as Field objects instead of + field names. If self.fields is None, defaults to putting every + non-AutoField field with editable=True in a single fieldset. + """ + if self.fields is None: + field_struct = ((None, {'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)]}),) + else: + field_struct = self.fields new_fieldset_list = [] - for fieldset in self.fields: + for fieldset in field_struct: new_fieldset = [fieldset[0], {}] new_fieldset[1].update(fieldset[1]) admin_fields = [] diff --git a/django/models/auth.py b/django/models/auth.py index 4d3f6394a1f..516ec112df8 100644 --- a/django/models/auth.py +++ b/django/models/auth.py @@ -20,9 +20,6 @@ class Group(meta.Model): ) ordering = (('name', 'ASC'),) admin = meta.Admin( - fields = ( - (None, {'fields': ('name', 'permissions')}), - ), search_fields = ('name',), ) diff --git a/django/models/core.py b/django/models/core.py index 4416f22b76c..bdf4567e6a2 100644 --- a/django/models/core.py +++ b/django/models/core.py @@ -65,9 +65,6 @@ class Redirect(meta.Model): unique_together=(('site_id', 'old_path'),) ordering = (('old_path', 'ASC'),) admin = meta.Admin( - fields = ( - (None, {'fields': ('site_id', 'old_path', 'new_path')}), - ), list_display = ('__repr__',), list_filter = ('site_id',), search_fields = ('old_path', 'new_path'), diff --git a/docs/model-api.txt b/docs/model-api.txt index e52ca8b43de..a2cfade8542 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -304,9 +304,9 @@ Field Types many toppings on a pizza):: meta.ForeignKey(Pizza) - + .. admonition:: Note - + To create a recursive relationship, use a ``ForeignKey`` that relates to ``"self"`` (i.e. ``meta.ForeignKey("self")``). @@ -568,7 +568,7 @@ Admin options The ``admin`` field in the model tells Django how to construct the admin interface for the object. The field is an instance of the ``meta.Admin`` -object, which has the following options (of which only ``fields`` is required): +object, which has the following options. All are optional. ``date_hierarchy`` To allow filtering of objects in the admin by date, set ``date_hierarchy`` @@ -616,6 +616,11 @@ object, which has the following options (of which only ``fields`` is required): .. image:: http://media.djangoproject.com/img/doc/flatfiles_admin.png + If ``fields`` isn't given but a model does define ``admin`` as a + ``meta.Admin`` object, Django will default to displaying each field that + isn't an ``AutoField`` and has ``editable=True``, in a single fieldset, in + the same order as the ``fields`` in the model. + ``js`` A list of strings representing URLs of JavaScript files to link into the admin screen. This can be used to tweak a given type of admin page in JS or diff --git a/docs/overview.txt b/docs/overview.txt index 1453b709643..86f089778db 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -138,15 +138,7 @@ classes:: meta.TextField('article'), meta.ForeignKey(Reporter), ) - admin = meta.Admin( - fields = ( - (None, {'fields': ('headline', 'article')}), - ('Extra stuff', {'fields': ('pub_date', 'reporter_id')}), - ), - ) - -The ``admin.fields`` defines the layout of your admin form. Each element in the -fields tuple corresponds to a ``