Opened 16 years ago
Closed 16 years ago
#9750 closed (wontfix)
Manager Documentation and Admin interface
Reported by: | mm | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | martin@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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()
Change History (3)
comment:1 by , 16 years ago
Cc: | added |
---|
comment:2 by , 16 years ago
comment:3 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This has been already reported in #9476, see that ticket for the rationale of why a code developer closed it as wontfix.