home / django_tickets / tickets

tickets: 8806

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8806 2008-09-02 18:38:01 2009-02-25 19:51:44 2022-03-06 03:43:13.075868 Unreviewed closed contrib.admin     dev duplicate ModelAdmin should allow not default manager 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: nobody alon ModelAdmin,Manager 0 1 0 0 0 0
Powered by Datasette · Queries took 1.372ms