110 | | (Yes, in this example, the admin options still live in the {{{models.py}}} file. But there's nothing that requires them to do so. The only requirement is that the {{{register()}}} calls are executed at some point, and putting them in the {{{models.py}}} is an easy way to ensure that. We'll likely come up with a nice convention for specifying admin options, perhaps in a file called {{{admin.py}}}.) |
| 110 | In this example, the admin options still live in the {{{models.py}}} file. But there's nothing that requires them to do so. The only requirement is that the {{{register()}}} calls are executed at some point, and putting them in the {{{models.py}}} is an easy way to ensure that. We'll likely come up with a nice convention for this.[[BR]] |
| 111 | A proposal 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. |
| 198 | |
| 199 | === Renamed 'fields' to 'fieldsets' === |
| 200 | |
| 201 | 'Fields' is used to order and group fields in the change form layout.[[BR]] |
| 202 | It is still available in the new admin, but it accepts only a list of fields. [[BR]] |
| 203 | In case one uses fieldsets to organize the fields, one needs to use 'fieldsets' instead. |
| 204 | |
| 205 | An example: |
| 206 | {{{ |
| 207 | #!python |
| 208 | |
| 209 | # OLD: |
| 210 | class MyModelA(models.Model): |
| 211 | class Admin: |
| 212 | fields = ('field1','field2','field3','field4') |
| 213 | |
| 214 | class MyModelB(models.Model): |
| 215 | class Admin: |
| 216 | fields = ( |
| 217 | ('group1', {'fields': ('field1','field2'),), |
| 218 | ('group2', {'fields': ('field3','field4'),), |
| 219 | ) |
| 220 | |
| 221 | # NEW: |
| 222 | class MyModelA_Options(admin.ModelAdmin): |
| 223 | fields = ('field1','field2','field3','field4') # Renaming is optional |
| 224 | |
| 225 | class MyModelB_Options(admin.ModelAdmin): |
| 226 | fieldsets = ( |
| 227 | ('group1', {'fields': ('field1','field2'),), |
| 228 | ('group2', {'fields': ('field3','field4'),), |
| 229 | ) |