| 117 | | '''A proposed convention''': Specifying all admin options in a file called {{{admin.py}}}, and import it in the {{{__init__.py}}} file of your application module to do the registering during the initialization. |
| | 117 | '''A proposed convention''': Specifying all admin options in a file called {{{admins.py}}}, and import it in the {{{__init__.py}}} file of your application module to do the registering during the initialization. In this case the above example would look like this: |
| | 118 | {{{ |
| | 119 | #!python |
| | 120 | # a sample models.py file |
| | 121 | from django.db import models |
| | 122 | |
| | 123 | class Author(models.Model): |
| | 124 | first_name = models.CharField(max_length=30) |
| | 125 | last_name = models.CharField(max_length=30) |
| | 126 | |
| | 127 | def __unicode__(self): |
| | 128 | return u'%s %s' % (self.first_name, self.last_name) |
| | 129 | |
| | 130 | class Book(models.Model): |
| | 131 | title = models.CharField(max_length=100) |
| | 132 | author = models.ForeignKey(Author) |
| | 133 | |
| | 134 | # a sample admins.py file |
| | 135 | from django.contrib import admin |
| | 136 | |
| | 137 | class BookAdmin(admin.ModelAdmin): |
| | 138 | list_display = ('title', 'author') |
| | 139 | ordering = ('title',) |
| | 140 | |
| | 141 | # a sample __init__.py file |
| | 142 | from django.contrib import admin |
| | 143 | from models import Author, Book |
| | 144 | from admins import BookAdmin |
| | 145 | |
| | 146 | admin.site.register(Author) |
| | 147 | admin.site.register(Book, BookAdmin) |
| | 148 | }}} |