| 477 | ==== Using a custom manager for the admin ==== |
| 478 | |
| 479 | Sometimes you'll ant to use a different manager for the admin displays (e.g. to display only objects matching some criteria in the admin). You can do this by defining the {{{manager}}} option in your {{{Admin}}} declaration: |
| 480 | |
| 481 | {{{ |
| 482 | #!python |
| 483 | |
| 484 | class LivingPeopleManager(models.Manager): |
| 485 | def get_query_set(self): |
| 486 | return super(LivingPeopleManager, self).get_query_set().filter(is_alive=True) |
| 487 | |
| 488 | class Person(models.Model): |
| 489 | name = models.CharField(maxlength=50) |
| 490 | is_alive = models.BooleanField() |
| 491 | |
| 492 | class Admin: |
| 493 | manager = LivingPeopleManager() |
| 494 | |
| 495 | }}} |
| 496 | |
| 497 | (see "You can override default QuerySets" for more on QuerySets) |
| 498 | |