Changeset 265
- Timestamp:
- 07/20/05 22:46:16 (3 years ago)
- Files:
-
- django/trunk/django/core/meta.py (modified) (2 diffs)
- django/trunk/django/models/auth.py (modified) (1 diff)
- django/trunk/django/models/core.py (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (3 diffs)
- django/trunk/docs/overview.txt (modified) (1 diff)
- django/trunk/docs/tutorial02.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/meta.py
r257 r265 2137 2137 2138 2138 class 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, 2140 2140 save_as=False, ordering=None, search_fields=None, save_on_top=False): 2141 2141 self.fields = fields … … 2149 2149 2150 2150 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 2153 2160 new_fieldset_list = [] 2154 for fieldset in self.fields:2161 for fieldset in field_struct: 2155 2162 new_fieldset = [fieldset[0], {}] 2156 2163 new_fieldset[1].update(fieldset[1]) django/trunk/django/models/auth.py
r262 r265 21 21 ordering = (('name', 'ASC'),) 22 22 admin = meta.Admin( 23 fields = (24 (None, {'fields': ('name', 'permissions')}),25 ),26 23 search_fields = ('name',), 27 24 ) django/trunk/django/models/core.py
r3 r265 66 66 ordering = (('old_path', 'ASC'),) 67 67 admin = meta.Admin( 68 fields = (69 (None, {'fields': ('site_id', 'old_path', 'new_path')}),70 ),71 68 list_display = ('__repr__',), 72 69 list_filter = ('site_id',), django/trunk/docs/model-api.txt
r257 r265 305 305 306 306 meta.ForeignKey(Pizza) 307 307 308 308 .. admonition:: Note 309 309 310 310 To create a recursive relationship, use a ``ForeignKey`` that relates 311 311 to ``"self"`` (i.e. ``meta.ForeignKey("self")``). … … 569 569 The ``admin`` field in the model tells Django how to construct the admin 570 570 interface 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):571 object, which has the following options. All are optional. 572 572 573 573 ``date_hierarchy`` … … 617 617 .. image:: http://media.djangoproject.com/img/doc/flatfiles_admin.png 618 618 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 619 624 ``js`` 620 625 A list of strings representing URLs of JavaScript files to link into the django/trunk/docs/overview.txt
r212 r265 139 139 meta.ForeignKey(Reporter), 140 140 ) 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() 150 142 151 143 The philosophy here is that your site is edited by a staff, or a client, or django/trunk/docs/tutorial02.txt
r261 r265 93 93 # ... 94 94 ) 95 admin = meta.Admin( 96 fields = ( 97 (None, {'fields': ('question', 'pub_date')}), 98 ), 99 ) 95 admin = meta.Admin() 100 96 101 97 Restart your development Web server, and reload the Django admin page. You'll … … 164 160 Take a few minutes to marvel at all the code you didn't have to write. 165 161 166 Let's customize this a bit. We can reorder the fields by changing the167 order of the field names in the ``admin`` attribute of the model::162 Let's customize this a bit. We can reorder the fields by explicitly adding a 163 ``fields`` parameter to ``meta.Admin``:: 168 164 169 165 admin = meta.Admin( … … 227 223 class Choice(meta.Model): 228 224 # ... 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() 238 226 239 227 Now "Choices" is an available option in the Django admin. The "Add choice" form … … 319 307 # ... 320 308 admin = meta.Admin( 321 fields = (322 (None, {'fields': ('question', 'pub_date')}),323 ),324 309 list_display = ('question', 'pub_date'), 325 310 )
