Django

Code

Changeset 265

Show
Ignore:
Timestamp:
07/20/05 22:46:16 (3 years ago)
Author:
adrian
Message:

Fixed #92 -- meta.Admin 'fields' parameter is now optional. If it's not given, Django will use all editable fields by default. This cuts down on redundancy. Also updated relevant docs to reflect the change.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/meta.py

    r257 r265  
    21372137 
    21382138class Admin: 
    2139     def __init__(self, fields, js=None, list_display=None, list_filter=None, date_hierarchy=None, 
     2139    def __init__(self, fields=None, js=None, list_display=None, list_filter=None, date_hierarchy=None, 
    21402140        save_as=False, ordering=None, search_fields=None, save_on_top=False): 
    21412141        self.fields = fields 
     
    21492149 
    21502150    def get_field_objs(self, opts): 
    2151         # Returns self.fields, except with fields as Field objects instead of 
    2152         # field names. 
     2151        """ 
     2152        Returns self.fields, except with fields as Field objects instead of 
     2153        field names. If self.fields is None, defaults to putting every 
     2154        non-AutoField field with editable=True in a single fieldset. 
     2155        """ 
     2156        if self.fields is None: 
     2157            field_struct = ((None, {'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)]}),) 
     2158        else: 
     2159            field_struct = self.fields 
    21532160        new_fieldset_list = [] 
    2154         for fieldset in self.fields
     2161        for fieldset in field_struct
    21552162            new_fieldset = [fieldset[0], {}] 
    21562163            new_fieldset[1].update(fieldset[1]) 
  • django/trunk/django/models/auth.py

    r262 r265  
    2121    ordering = (('name', 'ASC'),) 
    2222    admin = meta.Admin( 
    23         fields = ( 
    24             (None, {'fields': ('name', 'permissions')}), 
    25         ), 
    2623        search_fields = ('name',), 
    2724    ) 
  • django/trunk/django/models/core.py

    r3 r265  
    6666    ordering = (('old_path', 'ASC'),) 
    6767    admin = meta.Admin( 
    68         fields = ( 
    69             (None, {'fields': ('site_id', 'old_path', 'new_path')}), 
    70         ), 
    7168        list_display = ('__repr__',), 
    7269        list_filter = ('site_id',), 
  • django/trunk/docs/model-api.txt

    r257 r265  
    305305 
    306306        meta.ForeignKey(Pizza) 
    307          
     307 
    308308    .. admonition:: Note 
    309          
     309 
    310310        To create a recursive relationship, use a ``ForeignKey`` that relates 
    311311        to ``"self"`` (i.e. ``meta.ForeignKey("self")``). 
     
    569569The ``admin`` field in the model tells Django how to construct the admin 
    570570interface for the object.  The field is an instance of the ``meta.Admin`` 
    571 object, which has the following options (of which only ``fields`` is required): 
     571object, which has the following options. All are optional. 
    572572 
    573573``date_hierarchy`` 
     
    617617        .. image:: http://media.djangoproject.com/img/doc/flatfiles_admin.png 
    618618 
     619    If ``fields`` isn't given but a model does define ``admin`` as a 
     620    ``meta.Admin`` object, Django will default to displaying each field that 
     621    isn't an ``AutoField`` and has ``editable=True``, in a single fieldset, in 
     622    the same order as the ``fields`` in the model. 
     623 
    619624``js`` 
    620625    A list of strings representing URLs of JavaScript files to link into the 
  • django/trunk/docs/overview.txt

    r212 r265  
    139139            meta.ForeignKey(Reporter), 
    140140        ) 
    141         admin = meta.Admin( 
    142             fields = ( 
    143                 (None, {'fields': ('headline', 'article')}), 
    144                 ('Extra stuff', {'fields': ('pub_date', 'reporter_id')}), 
    145             ), 
    146         ) 
    147  
    148 The ``admin.fields`` defines the layout of your admin form. Each element in the 
    149 fields tuple corresponds to a ``<fieldset>`` in the form. 
     141        admin = meta.Admin() 
    150142 
    151143The philosophy here is that your site is edited by a staff, or a client, or 
  • django/trunk/docs/tutorial02.txt

    r261 r265  
    9393            # ... 
    9494        ) 
    95         admin = meta.Admin( 
    96             fields = ( 
    97                 (None, {'fields': ('question', 'pub_date')}), 
    98             ), 
    99         ) 
     95        admin = meta.Admin() 
    10096 
    10197Restart your development Web server, and reload the Django admin page. You'll 
     
    164160Take a few minutes to marvel at all the code you didn't have to write. 
    165161 
    166 Let's customize this a bit. We can reorder the fields by changing the 
    167 order of the field names in the ``admin`` attribute of the model:: 
     162Let's customize this a bit. We can reorder the fields by explicitly adding a 
     163``fields`` parameter to ``meta.Admin``:: 
    168164 
    169165        admin = meta.Admin( 
     
    227223    class Choice(meta.Model): 
    228224        # ... 
    229         admin = meta.Admin( 
    230             fields = ( 
    231                 (None, {'fields': ('poll_id', 'choice', 'votes')}), 
    232             ), 
    233         ) 
    234  
    235 (Note that we used "poll_id" to refer to the ``ForeignKey(Poll)`` field. The 
    236 field name is automatically calculated from the model's class name, lowercased, 
    237 plus '_id'.) 
     225        admin = meta.Admin() 
    238226 
    239227Now "Choices" is an available option in the Django admin. The "Add choice" form 
     
    319307        # ... 
    320308        admin = meta.Admin( 
    321             fields = ( 
    322                 (None, {'fields': ('question', 'pub_date')}), 
    323             ), 
    324309            list_display = ('question', 'pub_date'), 
    325310        )