Changes between Version 74 and Version 75 of RemovingTheMagic


Ignore:
Timestamp:
02/25/2006 01:49:52 PM (9 years ago)
Author:
jacob
Comment:

Added information about Admin managers

Legend:

Unmodified
Added
Removed
Modified
  • RemovingTheMagic

    v74 v75  
    475475}}}
    476476
     477==== Using a custom manager for the admin ====
     478
     479Sometimes 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
     484class LivingPeopleManager(models.Manager):
     485    def get_query_set(self):
     486        return super(LivingPeopleManager, self).get_query_set().filter(is_alive=True)
     487
     488class 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
    477499=== Added a more powerful way of overriding model methods, removed hard-coded _pre_save(), _post_save(), etc. ===
    478500
Back to Top