#9750: Manager Documentation and Admin interface
---------------------------+------------------------------------------------
 Reporter:  mm             |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Documentation  |     Version:  1.0       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 In http://docs.djangoproject.com/en/dev/topics/db/managers/ it says:

 {{{
 If you use custom Manager objects, take note that the first Manager Django
 encounters
 (in the order in which they're defined in the model) has a special status.
 Django
 interprets this first Manager defined in a class as the "default" Manager,
 and several
 parts of Django (though not the admin application) will use that Manager
 exclusively for
 that model. As a result, it's often a good idea to be careful in your
 choice of default
 manager, in order to avoid a situation where overriding of get_query_set()
 results in an
 inability to retrieve objects you'd like to work with.
 }}}

 I found this to be wrong. The admin interface will only list the objects
 that are in the queryset that the default manager returns

 This will only return objects with a status of `finished=True` in the
 admin, it's not even possible to access them directly by URL (default is
 to create objects that won't show)

 Note: code written from scratch but you should get the idea, mind the
 order of appearance of the managers...
 {{{
 from django.db import models
 from django.contrib import admin

 class FinishedManager(models.Manager):
     def get_query_set(self):
         return super(FinishedManager,
 self).get_query_set().filter(finished=True)

 class Todo(models.Model):
     title = models.CharField(max_length=250)
     finished = models.BooleanField(default=False)

     finished_objects = FinishedManager()
     objects = models.Manager()


 class TodoAdmin(admin.ModelAdmin):
     model = Todo

 admin.site.register(Todo, TodoAdmin)
 }}}

 while having a `Todo`-class like below will return all objects:

 {{{
 class Todo(models.Model):
     title = models.CharField(max_length=250)
     finished = models.BooleanField(default=False)

     objects = models.Manager()
     finished_objects = FinishedManager()
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9750>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to