Changeset 7616
- Timestamp:
- 06/11/08 13:01:14 (5 months ago)
- Files:
-
- django/branches/newforms-admin/docs/admin.txt (modified) (1 diff)
- django/branches/newforms-admin/docs/model-api.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin/docs/admin.txt
r6329 r7616 36 36 ====================== 37 37 38 The ``ModelAdmin`` class is the representation of a model in the admin 39 interface. These are stored in a file named ``admin.py`` in your application. 40 Let's take a look at a very simple example the ``ModelAdmin``:: 41 42 from django.contrib import admin 43 from myproject.myapp.models import Author 44 45 class AuthorAdmin(admin.ModelAdmin): 46 pass 47 admin.site.register(Author, AuthorAdmin) 48 49 The ``ModelAdmin`` is very flexible. It has several options for dealing with 50 customizing the interface. All options are defined on the ``ModelAdmin`` 51 subclass:: 52 53 class AuthorAdmin(admin.ModelAdmin): 54 date_hierarchy = 'pub_date' 55 56 ``date_hierarchy`` 57 ------------------ 58 59 Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` in 60 your model, and the change list page will include a date-based drilldown 61 navigation by that field. 62 63 Example:: 64 65 date_hierarchy = 'pub_date' 66 67 ``fieldsets`` 68 ------------- 69 70 Set ``fieldsets`` to control the layout of admin "add" and "change" pages. 71 72 ``fieldsets`` is a list of two-tuples, in which each two-tuple represents a 73 ``<fieldset>`` on the admin form page. (A ``<fieldset>`` is a "section" of the 74 form.) 75 76 The two-tuples are in the format ``(name, field_options)``, where ``name`` is a 77 string representing the title of the fieldset and ``field_options`` is a 78 dictionary of information about the fieldset, including a list of fields to be 79 displayed in it. 80 81 A full example, taken from the ``django.contrib.flatpages.FlatPage`` model:: 82 83 class FlatPageAdmin(admin.ModelAdmin): 84 fieldsets = ( 85 (None, { 86 'fields': ('url', 'title', 'content', 'sites') 87 }), 88 ('Advanced options', { 89 'classes': ('collapse',), 90 'fields': ('enable_comments', 'registration_required', 'template_name') 91 }), 92 ) 93 94 This results in an admin page that looks like: 95 96 .. image:: http://media.djangoproject.com/img/doc/flatfiles_admin.png 97 98 If ``fieldsets`` isn't given, Django will default to displaying each field 99 that isn't an ``AutoField`` and has ``editable=True``, in a single fieldset, 100 in the same order as the fields are defined in the model. 101 102 The ``field_options`` dictionary can have the following keys: 103 104 ``fields`` 105 ~~~~~~~~~~ 106 107 A tuple of field names to display in this fieldset. This key is required. 108 109 Example:: 110 111 { 112 'fields': ('first_name', 'last_name', 'address', 'city', 'state'), 113 } 114 115 To display multiple fields on the same line, wrap those fields in their own 116 tuple. In this example, the ``first_name`` and ``last_name`` fields will 117 display on the same line:: 118 119 { 120 'fields': (('first_name', 'last_name'), 'address', 'city', 'state'), 121 } 122 123 ``classes`` 124 ~~~~~~~~~~~ 125 126 A string containing extra CSS classes to apply to the fieldset. 127 128 Example:: 129 130 { 131 'classes': 'wide', 132 } 133 134 Apply multiple classes by separating them with spaces. Example:: 135 136 { 137 'classes': 'wide extrapretty', 138 } 139 140 Two useful classes defined by the default admin-site stylesheet are 141 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be 142 initially collapsed in the admin and replaced with a small "click to expand" 143 link. Fieldsets with the ``wide`` style will be given extra horizontal space. 144 145 ``description`` 146 ~~~~~~~~~~~~~~~ 147 148 A string of optional extra text to be displayed at the top of each fieldset, 149 under the heading of the fieldset. It's used verbatim, so you can use any HTML 150 and you must escape any special HTML characters (such as ampersands) yourself. 151 152 ``list_display`` 153 ---------------- 154 155 Set ``list_display`` to control which fields are displayed on the change list 156 page of the admin. 157 158 Example:: 159 160 list_display = ('first_name', 'last_name') 161 162 If you don't set ``list_display``, the admin site will display a single column 163 that displays the ``__unicode__()`` representation of each object. 164 165 A few special cases to note about ``list_display``: 166 167 * If the field is a ``ForeignKey``, Django will display the 168 ``__unicode__()`` of the related object. 169 170 * ``ManyToManyField`` fields aren't supported, because that would entail 171 executing a separate SQL statement for each row in the table. If you 172 want to do this nonetheless, give your model a custom method, and add 173 that method's name to ``list_display``. (See below for more on custom 174 methods in ``list_display``.) 175 176 * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will 177 display a pretty "on" or "off" icon instead of ``True`` or ``False``. 178 179 * If the string given is a method of the model, Django will call it and 180 display the output. This method should have a ``short_description`` 181 function attribute, for use as the header for the field. 182 183 Here's a full example model:: 184 185 class Person(models.Model): 186 name = models.CharField(max_length=50) 187 birthday = models.DateField() 188 189 def decade_born_in(self): 190 return self.birthday.strftime('%Y')[:3] + "0's" 191 decade_born_in.short_description = 'Birth decade' 192 193 class PersonAdmin(admin.ModelAdmin): 194 list_display = ('name', 'decade_born_in') 195 196 * If the string given is a method of the model, Django will HTML-escape the 197 output by default. If you'd rather not escape the output of the method, 198 give the method an ``allow_tags`` attribute whose value is ``True``. 199 200 Here's a full example model:: 201 202 class Person(models.Model): 203 first_name = models.CharField(max_length=50) 204 last_name = models.CharField(max_length=50) 205 color_code = models.CharField(max_length=6) 206 207 def colored_name(self): 208 return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name) 209 colored_name.allow_tags = True 210 211 class PersonAdmin(admin.ModelAdmin): 212 list_display = ('first_name', 'last_name', 'colored_name') 213 214 * If the string given is a method of the model that returns True or False 215 Django will display a pretty "on" or "off" icon if you give the method a 216 ``boolean`` attribute whose value is ``True``. 217 218 Here's a full example model:: 219 220 class Person(models.Model): 221 first_name = models.CharField(max_length=50) 222 birthday = models.DateField() 223 224 def born_in_fifties(self): 225 return self.birthday.strftime('%Y')[:3] == 5 226 born_in_fifties.boolean = True 227 228 class PersonAdmin(admin.ModelAdmin): 229 list_display = ('name', 'born_in_fifties') 230 231 232 * The ``__str__()`` and ``__unicode__()`` methods are just as valid in 233 ``list_display`` as any other model method, so it's perfectly OK to do 234 this:: 235 236 list_display = ('__unicode__', 'some_other_field') 237 238 * Usually, elements of ``list_display`` that aren't actual database fields 239 can't be used in sorting (because Django does all the sorting at the 240 database level). 241 242 However, if an element of ``list_display`` represents a certain database 243 field, you can indicate this fact by setting the ``admin_order_field`` 244 attribute of the item. 245 246 For example:: 247 248 class Person(models.Model): 249 first_name = models.CharField(max_length=50) 250 color_code = models.CharField(max_length=6) 251 252 def colored_first_name(self): 253 return '<span style="color: #%s;">%s</span>' % (self.color_code, self.first_name) 254 colored_first_name.allow_tags = True 255 colored_first_name.admin_order_field = 'first_name' 256 257 class PersonAdmin(admin.ModelAdmin): 258 list_display = ('first_name', 'colored_first_name') 259 260 The above will tell Django to order by the ``first_name`` field when 261 trying to sort by ``colored_first_name`` in the admin. 262 263 ``list_display_links`` 264 ---------------------- 265 266 Set ``list_display_links`` to control which fields in ``list_display`` should 267 be linked to the "change" page for an object. 268 269 By default, the change list page will link the first column -- the first field 270 specified in ``list_display`` -- to the change page for each item. But 271 ``list_display_links`` lets you change which columns are linked. Set 272 ``list_display_links`` to a list or tuple of field names (in the same format as 273 ``list_display``) to link. 274 275 ``list_display_links`` can specify one or many field names. As long as the 276 field names appear in ``list_display``, Django doesn't care how many (or how 277 few) fields are linked. The only requirement is: If you want to use 278 ``list_display_links``, you must define ``list_display``. 279 280 In this example, the ``first_name`` and ``last_name`` fields will be linked on 281 the change list page:: 282 283 class PersonAdmin(admin.ModelAdmin): 284 list_display = ('first_name', 'last_name', 'birthday') 285 list_display_links = ('first_name', 'last_name') 286 287 Finally, note that in order to use ``list_display_links``, you must define 288 ``list_display``, too. 289 290 ``list_filter`` 291 --------------- 292 293 Set ``list_filter`` to activate filters in the right sidebar of the change list 294 page of the admin. This should be a list of field names, and each specified 295 field should be either a ``BooleanField``, ``CharField``, ``DateField``, 296 ``DateTimeField``, ``IntegerField`` or ``ForeignKey``. 297 298 This example, taken from the ``django.contrib.auth.models.User`` model, shows 299 how both ``list_display`` and ``list_filter`` work:: 300 301 class UserAdmin(admin.ModelAdmin): 302 list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff') 303 list_filter = ('is_staff', 'is_superuser') 304 305 The above code results in an admin change list page that looks like this: 306 307 .. image:: http://media.djangoproject.com/img/doc/users_changelist.png 308 309 (This example also has ``search_fields`` defined. See below.) 310 311 ``list_per_page`` 312 ----------------- 313 314 Set ``list_per_page`` to control how many items appear on each paginated admin 315 change list page. By default, this is set to ``100``. 316 317 ``list_select_related`` 318 ----------------------- 319 320 Set ``list_select_related`` to tell Django to use ``select_related()`` in 321 retrieving the list of objects on the admin change list page. This can save you 322 a bunch of database queries. 323 324 The value should be either ``True`` or ``False``. Default is ``False``. 325 326 Note that Django will use ``select_related()``, regardless of this setting, 327 if one of the ``list_display`` fields is a ``ForeignKey``. 328 329 For more on ``select_related()``, see `the select_related() docs`_. 330 331 .. _the select_related() docs: ../db-api/#select-related 332 333 ``ordering`` 334 ------------ 335 336 Set ``ordering`` to specify how objects on the admin change list page should be 337 ordered. This should be a list or tuple in the same format as a model's 338 ``ordering`` parameter. 339 340 If this isn't provided, the Django admin will use the model's default ordering. 341 342 ``save_as`` 343 ----------- 344 345 Set ``save_as`` to enable a "save as" feature on admin change forms. 346 347 Normally, objects have three save options: "Save", "Save and continue editing" 348 and "Save and add another". If ``save_as`` is ``True``, "Save and add another" 349 will be replaced by a "Save as" button. 350 351 "Save as" means the object will be saved as a new object (with a new ID), 352 rather than the old object. 353 354 By default, ``save_as`` is set to ``False``. 355 356 ``save_on_top`` 357 --------------- 358 359 Set ``save_on_top`` to add save buttons across the top of your admin change 360 forms. 361 362 Normally, the save buttons appear only at the bottom of the forms. If you set 363 ``save_on_top``, the buttons will appear both on the top and the bottom. 364 365 By default, ``save_on_top`` is set to ``False``. 366 367 ``search_fields`` 368 ----------------- 369 370 Set ``search_fields`` to enable a search box on the admin change list page. 371 This should be set to a list of field names that will be searched whenever 372 somebody submits a search query in that text box. 373 374 These fields should be some kind of text field, such as ``CharField`` or 375 ``TextField``. You can also perform a related lookup on a ``ForeignKey`` with 376 the lookup API "follow" notation:: 377 378 search_fields = ['foreign_key__related_fieldname'] 379 380 When somebody does a search in the admin search box, Django splits the search 381 query into words and returns all objects that contain each of the words, case 382 insensitive, where each word must be in at least one of ``search_fields``. For 383 example, if ``search_fields`` is set to ``['first_name', 'last_name']`` and a 384 user searches for ``john lennon``, Django will do the equivalent of this SQL 385 ``WHERE`` clause:: 386 387 WHERE (first_name ILIKE '%john%' OR last_name ILIKE '%john%') 388 AND (first_name ILIKE '%lennon%' OR last_name ILIKE '%lennon%') 389 390 For faster and/or more restrictive searches, prefix the field name 391 with an operator: 392 393 ``^`` 394 Matches the beginning of the field. For example, if ``search_fields`` is 395 set to ``['^first_name', '^last_name']`` and a user searches for 396 ``john lennon``, Django will do the equivalent of this SQL ``WHERE`` 397 clause:: 398 399 WHERE (first_name ILIKE 'john%' OR last_name ILIKE 'john%') 400 AND (first_name ILIKE 'lennon%' OR last_name ILIKE 'lennon%') 401 402 This query is more efficient than the normal ``'%john%'`` query, because 403 the database only needs to check the beginning of a column's data, rather 404 than seeking through the entire column's data. Plus, if the column has an 405 index on it, some databases may be able to use the index for this query, 406 even though it's a ``LIKE`` query. 407 408 ``=`` 409 Matches exactly, case-insensitive. For example, if 410 ``search_fields`` is set to ``['=first_name', '=last_name']`` and 411 a user searches for ``john lennon``, Django will do the equivalent 412 of this SQL ``WHERE`` clause:: 413 414 WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john') 415 AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') 416 417 Note that the query input is split by spaces, so, following this example, 418 it's currently not possible to search for all records in which 419 ``first_name`` is exactly ``'john winston'`` (containing a space). 420 421 ``@`` 422 Performs a full-text match. This is like the default search method but uses 423 an index. Currently this is only available for MySQL. 424 38 425 ``AdminSite`` objects 39 426 ===================== django/branches/newforms-admin/docs/model-api.txt
r7492 r7616 13 13 * Model metadata (non-field information) goes in an inner class named 14 14 ``Meta``. 15 * Metadata used for Django's admin site goes into an inner class named16 ``Admin``.17 15 * With all of this, Django gives you an automatically-generated 18 16 database-access API, which is explained in the `Database API reference`_. … … 823 821 Argument Description 824 822 ======================= ============================================================ 825 ``edit_inline`` If not ``False``, this related object is edited826 "inline" on the related object's page. This means827 that the object will not have its own admin828 interface. Use either ``models.TABULAR`` or ``models.STACKED``,829 which, respectively, designate whether the inline-editable830 objects are displayed as a table or as a "stack" of831 fieldsets.832 833 823 ``limit_choices_to`` A dictionary of lookup arguments and values (see 834 824 the `Database API reference`_) that limit the … … 848 838 849 839 Not compatible with ``edit_inline``. 850 851 ``max_num_in_admin`` For inline-edited objects, this is the maximum852 number of related objects to display in the admin.853 Thus, if a pizza could only have up to 10854 toppings, ``max_num_in_admin=10`` would ensure855 that a user never enters more than 10 toppings.856 857 Note that this doesn't ensure more than 10 related858 toppings ever get created. It simply controls the859 admin interface; it doesn't enforce things at the860 Python API level or database level.861 862 ``min_num_in_admin`` The minimum number of related objects displayed in863 the admin. Normally, at the creation stage,864 ``num_in_admin`` inline objects are shown, and at865 the edit stage ``num_extra_on_change`` blank866 objects are shown in addition to all pre-existing867 related objects. However, no fewer than868 ``min_num_in_admin`` related objects will ever be869 displayed.870 871 ``num_extra_on_change`` The number of extra blank related-object fields to872 show at the change stage.873 874 ``num_in_admin`` The default number of inline objects to display875 on the object page at the add stage.876 877 ``raw_id_admin`` Only display a field for the integer to be entered878 instead of a drop-down menu. This is useful when879 related to an object type that will have too many880 rows to make a select box practical.881 882 Not used with ``edit_inline``.883 840 884 841 ``related_name`` The name to use for the relation from the related … … 957 914 ======================= ============================================================ 958 915 ``related_name`` See the description under ``ForeignKey`` above. 959 960 ``filter_interface`` Use a nifty unobtrusive Javascript "filter" interface961 instead of the usability-challenged ``<select multiple>``962 in the admin form for this object. The value should be963 ``models.HORIZONTAL`` or ``models.VERTICAL`` (i.e.964 should the interface be stacked horizontally or965 vertically).966 916 967 917 ``limit_choices_to`` See the description under ``ForeignKey`` above. … … 1255 1205 value, just as you would for any other attribute, and it will update the 1256 1206 correct field in the model. 1257 1258 Admin options1259 =============1260 1261 If you want your model to be visible to Django's admin site, give your model an1262 inner ``"class Admin"``, like so::1263 1264 class Person(models.Model):1265 first_name = models.CharField(max_length=30)1266 last_name = models.CharField(max_length=30)1267 1268 class Admin:1269 # Admin options go here1270 pass1271 1272 The ``Admin`` class tells Django how to display the model in the admin site.1273 1274 Here's a list of all possible ``Admin`` options. None of these options are1275 required. To use an admin interface without specifying any options, use1276 ``pass``, like so::1277 1278 class Admin:1279 pass1280 1281 Adding ``class Admin`` to a model is completely optional.1282 1283 ``date_hierarchy``1284 ------------------1285 1286 Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` in1287 your model, and the change list page will include a date-based drilldown1288 navigation by that field.1289 1290 Example::1291 1292 date_hierarchy = 'pub_date'1293 1294 ``fields``1295 ----------1296 1297 Set ``fields`` to control the layout of admin "add" and "change" pages.1298 1299 ``fields`` is a list of two-tuples, in which each two-tuple represents a1300 ``<fieldset>`` on the admin form page. (A ``<fieldset>`` is a "section" of the1301 form.)1302 1303 The two-tuples are in the format ``(name, field_options)``, where ``name`` is a1304 string representing the title of the fieldset and ``field_options`` is a1305 dictionary of information about the fieldset, including a list of fields to be1306 displayed in it.1307 1308 A full example, taken from the ``django.contrib.flatpages.FlatPage`` model::1309 1310 class Admin:1311 fields = (1312 (None, {1313 'fields': ('url', 'title', 'content', 'sites')1314 }),1315 ('Advanced options', {1316 'classes': 'collapse',1317 'fields' : ('enable_comments', 'registration_required', 'template_name')1318 }),1319 )1320 1321 This results in an admin page that looks like:1322 1323 .. image:: http://media.djangoproject.com/img/doc/flatfiles_admin.png1324 1325 If ``fields`` isn't given, Django will default to displaying each field that1326 isn't an ``AutoField`` and has ``editable=True``, in a single fieldset, in1327 the same order as the fields are defined in the model.1328 1329 The ``field_options`` dictionary can have the following keys:1330 1331 ``fields``1332 ~~~~~~~~~~1333 1334 A tuple of field names to display in this fieldset. This key is required.1335 1336 Example::1337 1338 {1339 'fields': ('first_name', 'last_name', 'address', 'city', 'state'),1340 }1341 1342 To display multiple fields on the same line, wrap those fields in their own1343 tuple. In this example, the ``first_name`` and ``last_name`` fields will1344 display on the same line::1345 1346 {1347 'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),1348 }1349 1350 ``classes``1351 ~~~~~~~~~~~1352 1353 A string containing extra CSS classes to apply to the fieldset.1354 1355 Example::1356 1357 {1358 'classes': 'wide',1359 }1360 1361 Apply multiple classes by separating them with spaces. Example::1362 1363 {1364 'classes': 'wide extrapretty',1365 }1366 1367 Two useful classes defined by the default admin-site stylesheet are1368 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be1369 initially collapsed in the admin and replaced with a small "click to expand"1370 link. Fieldsets with the ``wide`` style will be given extra horizontal space.1371 1372 ``description``1373 ~~~~~~~~~~~~~~~1374 1375 A string of optional extra text to be displayed at the top of each fieldset,1376 under the heading of the fieldset. It's used verbatim, so you can use any HTML1377 and you must escape any special HTML characters (such as ampersands) yourself.1378 1379 ``js``1380 ------1381 1382 A list of strings representing URLs of JavaScript files to link into the admin1383 screen via ``<script src="">`` tags. This can be used to tweak a given type of1384 admin page in JavaScript or to provide "quick links" to fill in default values1385 for certain fields.1386 1387 If you use relative URLs -- URLs that don't start with ``http://`` or ``/`` --1388 then the admin site will automatically prefix these links with1389 ``settings.ADMIN_MEDIA_PREFIX``.1390 1391 ``list_display``1392 ----------------1393 1394 Set ``list_display`` to control which fields are displayed on the change list1395 page of the admin.1396 1397 Example::1398 1399 list_display = ('first_name', 'last_name')1400 1401 If you don't set ``list_display``, the admin site will display a single column1402 that displays the ``__str__()`` representation of each object.1403 1404 A few special cases to note about ``list_display``:1405 1406 * If the field is a ``ForeignKey``, Django will display the1407 ``__unicode__()`` of the related object.1408 1409 * ``ManyToManyField`` fields aren't supported, because that would entail1410 executing a separate SQL statement for each row in the table. If you1411 want to do this nonetheless, give your model a custom method, and add1412 that method's name to ``list_display``. (See below for more on custom1413 methods in ``list_display``.)1414 1415 * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will1416 display a pretty "on" or "off" icon instead of ``True`` or ``False``.1417 1418 * If the string given is a method of the model, Django will call it and1419 display the output. This method should have a ``short_description``1420 function attribute, for use as the header for the field.1421 1422 Here's a full example model::1423 1424 class Person(models.Model):1425 name = models.CharField(max_length=50)1426 birthday = models.DateField()1427 1428 class Admin:1429 list_display = ('name', 'decade_born_in')1430 1431 def decade_born_in(self):1432 return self.birthday.strftime('%Y')[:3] + "0's"1433 decade_born_in.short_description = 'Birth decade'1434 1435 * If the string given is a method of the model, Django will HTML-escape the1436 output by default. If you'd rather not escape the output of the method,1437 give the method an ``allow_tags`` attribute whose value is ``True``.1438 1439 Here's a full example model::1440 1441 class Person(models.Model):1442 first_name = models.CharField(max_length=50)1443 last_name = models.CharField(max_length=50)1444 color_code = models.CharField(max_length=6)1445 1446 class Admin:1447 list_display = ('first_name', 'last_name', 'colored_name')1448 1449 def colored_name(self):1450 return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)1451 colored_name.allow_tags = True1452 1453 * If the string given is a method of the model that returns True or False1454 Django will display a pretty "on" or "off" icon if you give the method a1455 ``boolean`` attribute whose value is ``True``.1456 1457 Here's a full example model::1458 1459 class Person(models.Model):1460 first_name = models.CharField(max_length=50)1461 birthday = models.DateField()1462 1463 class Admin:1464 list_display = ('name', 'born_in_fifties')1465 1466 def born_in_fifties(self):1467 return self.birthday.strftime('%Y')[:3] == 51468 born_in_fifties.boolean = True1469 1470 1471 * The ``__str__()`` and ``__unicode__()`` methods are just as valid in1472 ``list_display`` as any other model method, so it's perfectly OK to do1473 this::1474 1475 list_display = ('__unicode__', 'some_other_field')1476 1477 * Usually, elements of ``list_display`` that aren't actual database fields1478 can't be used in sorting (because Django does all the sorting at the1479 database level).1480 1481 However, if an element of ``list_display`` represents a certain database1482 field, you can indicate this fact by setting the ``admin_order_field``1483 attribute of the item.1484 1485 For example::1486 1487 class Person(models.Model):1488 first_name = models.CharField(max_length=50)1489 color_code = models.CharField(max_length=6)1490 1491 class Admin:1492 list_display = ('first_name', 'colored_first_name')1493 1494 def colored_first_name(self):1495 return '<span style="color: #%s;">%s</span>' % (self.color_code, self.first_name)1496 colored_first_name.allow_tags = True1497 colored_first_name.admin_order_field = 'first_name'1498 1499 The above will tell Django to order by the ``first_name`` field when1500 trying to sort by ``colored_first_name`` in the admin.1501 1502 ``list_display_links``1503 ----------------------1504 1505 Set ``list_display_links`` to control which fields in ``list_display`` should1506 be linked to the "change" page for an object.1507 1508 By default, the change list page will link the first column -- the first field1509 specified in ``list_display`` -- to the change page for each item. But1510 ``list_display_links`` lets you change which columns are linked. Set1511 ``list_display_links`` to a list or tuple of field names (in the same format as1512 ``list_display``) to link.1513 1514 ``list_display_links`` can specify one or many field names. As long as the1515 field names appear in ``list_display``, Django doesn't care how many (or how1516 few) fields are linked. The only requirement is: If you want to use1517 ``list_display_links``, you must define ``list_display``.1518 1519 In this example, the ``first_name`` and ``last_name`` fields will be linked on1520 the change list page::1521 1522 class Admin:1523 list_display = ('first_name', 'last_name', 'birthday')1524 list_display_links = ('first_name', 'last_name')1525 1526 Finally, note that in order to use ``list_display_links``, you must define1527 ``list_display``, too.1528 1529 ``list_filter``1530 ---------------1531 1532 Set ``list_filter`` to activate filters in the right sidebar of the change list1533 page of the admin. This should be a list of field names, and each specified1534 field should be either a ``BooleanField``, ``CharField``, ``DateField``,1535 ``DateTimeField``, ``IntegerField`` or ``ForeignKey``.1536 1537 This example, taken from the ``django.contrib.auth.models.User`` model, shows1538 how both ``list_display`` and ``list_filter`` work::1539 1540 class Admin:1541 list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')1542 list_filter = ('is_staff', 'is_superuser')1543 1544 The above code results in an admin change list page that looks like this:1545 1546 .. image:: http://media.djangoproject.com/img/doc/users_changelist.png1547 1548 (This example also has ``search_fields`` defined. See below.)1549 1550 ``list_per_page``1551 -----------------1552 1553 Set ``list_per_page`` to control how many items appear on each paginated admin1554 change list page. By default, this is set to ``100``.1555 1556 ``list_select_related``1557 -----------------------1558 1559 Set ``list_select_related`` to tell Django to use ``select_related()`` in1560 retrieving the list of objects on the admin change list page. This can save you1561 a bunch of database queries.1562 1563 The value should be either ``True`` or ``False``. Default is ``False``.1564 1565 Note that Django will use ``select_related()``, regardless of this setting,1566 if one of the ``list_display`` fields is a ``ForeignKey``.1567 1568 For more on ``select_related()``, see `the select_related() docs`_.1569 1570 .. _the select_related() docs: ../db-api/#select-related1571 1572 ``ordering``1573 ------------1574 1575 Set ``ordering`` to specify how objects on the admin change list page should be1576 ordered. This should be a list or tuple in the same format as a model's1577 ``ordering`` parameter.1578 1579 If this isn't provided, the Django admin will use the model's default ordering.1580 1581 ``save_as``1582 -----------1583 1584 Set ``save_as`` to enable a "save as" feature on admin change forms.1585 1586 Normally, objects have three save options: "Save", "Save and continue editing"1587 and "Save and add another". If ``save_as`` is ``True``, "Save and add another"1588 will be replaced by a "Save as" button.1589 1590 "Save as" means the object will be saved as a new object (with a new ID),1591 rather than the old object.1592 1593 By default, ``save_as`` is set to ``False``.1594 1595 ``save_on_top``1596 ---------------1597 1598 Set ``save_on_top`` to add save buttons across the top of your admin change1599 forms.1600 1601 Normally, the save buttons appear only at the bottom of the forms. If you set1602 ``save_on_top``, the buttons will appear both on the top and the bottom.1603 1604 By default, ``save_on_top`` is set to ``False``.1605 1606 ``search_fields``1607 -----------------1608 1609 Set ``search_fields`` to enable a search box on the admin change list page.1610 This should be set to a list of field names that will be searched whenever1611 somebody submits a search query in that text box.1612 1613 These fields should be some kind of text field, such as ``CharField`` or1614 ``TextField``. You can also perform a related lookup on a ``ForeignKey`` with1615 the lookup API "follow" notation::1616 1617 search_fields = ['foreign_key__related_fieldname']1618 1619 When somebody does a search in the admin search box, Django splits the search1620 query into words and returns all objects that contain each of the words, case1621 insensitive, where each word must be in at least one of ``search_fields``. For1622 example, if ``search_fields`` is set to ``['first_name', 'last_name']`` and a1623 user searches for ``john lennon``, Django will do the equivalent of this SQL1624 ``WHERE`` clause::1625 1626 WHERE (first_name ILIKE '%john%' OR last_name ILIKE '%john%')1627 AND (first_name ILIKE '%lennon%' OR last_name ILIKE '%lennon%')1628 1629 For faster and/or more restrictive searches, prefix the field name1630 with an operator:1631 1632 ``^``1633 Matches the beginning of the field. For example, if ``search_fields`` is1634 set to ``['^first_name', '^last_name']`` and a user searches for1635 ``john lennon``, Django will do the equivalent of this SQL ``WHERE``1636 clause::1637 1638 WHERE (first_name ILIKE 'john%' OR last_name ILIKE 'john%')1639 AND (first_name ILIKE 'lennon%' OR last_name ILIKE 'lennon%')1640 1641 This query is more efficient than the normal ``'%john%'`` query, because1642 the database only needs to check the beginning of a column's data, rather1643 than seeking through the entire column's data. Plus, if the column has an1644 index on it, some databases may be able to use the index for this query,1645 even though it's a ``LIKE`` query.1646 1647 ``=``1648 Matches exactly, case-insensitive. For example, if1649 ``search_fields`` is set to ``['=first_name', '=last_name']`` and1650 a user searches for ``john lennon``, Django will do the equivalent1651 of this SQL ``WHERE`` clause::1652 1653 WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john')1654 AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon')1655 1656 Note that the query input is split by spaces, so, following this example,1657 it's currently not possible to search for all records in which1658 ``first_name`` is exactly ``'john winston'`` (containing a space).1659 1660 ``@``1661 Performs a full-text match. This is like the default search method but uses1662 an index. Currently this is only available for MySQL.1663 1207 1664 1208 Managers
