Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#8806 closed (duplicate)

ModelAdmin should allow not default manager

Reported by: alon Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: ModelAdmin, Manager
Cc: alonlevy1@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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/

# my code
from django.contrib import admin

class MyAdmin(admin.ModelAdmin):

model = MyModel
manager = MyModel.othermanager

# unified diff against django/contrib/admin/ svn 8851
--- a/django/contrib/admin/
+++ b/django/contrib/admin/
@@ -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)

model_admin_manager.patch (1.0 KB) - added by alon 7 years ago.

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by alon

comment:1 Changed 7 years ago by scel

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This is pretty much a duplicate of #7510 (which has a required additional patch and more info).

comment:2 Changed 7 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top