#8806 closed (duplicate)
ModelAdmin should allow not default manager
Reported by: | Alon Levy | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ModelAdmin, Manager | |
Cc: | alonlevy1@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My use case is this:
I have a model with two Managers - one named objects (the default), and another one. I want the admin to use the non-default one (in my case I can't even give it the default one since it doesn't return instances of the model, but of another model it inherits from). So my solution (It doesn't even merit a patch - its just 3 lines changed in django/contrib/admin/options.py):
# my code
from django.contrib import admin
class MyAdmin(admin.ModelAdmin):
model = MyModel
manager = MyModel.othermanager
# unified diff against django/contrib/admin/options.py svn 8851
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -166,6 +166,8 @@ class ModelAdmin(BaseModelAdmin):
ordering = None
inlines = []
+ manager = None
+
# Custom templates (designed to be over-ridden in subclasses)
change_form_template = None
change_list_template = None
@@ -239,7 +241,10 @@ class ModelAdmin(BaseModelAdmin):
Returns a QuerySet of all model instances that can be edited by the
admin site. This is used by changelist_view.
"""
- qs = self.model._default_manager.get_query_set()
+ if self.manager is None:
+ qs = self.model._default_manager.get_query_set()
+ else:
+ qs = self.manager.get_query_set()
# TODO: this should be handled by some parameter to the ChangeList.
ordering = self.ordering or () # otherwise we might try to *None, which is bad ;)
if ordering:
Attachments (1)
Change History (3)
by , 16 years ago
Attachment: | model_admin_manager.patch added |
---|
comment:1 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is pretty much a duplicate of #7510 (which has a required additional patch and more info).