#8806: ModelAdmin should allow not default manager
--------------------------------+-------------------------------------------
 Reporter:  alon                |       Owner:  nobody    
   Status:  new                 |   Milestone:  post-1.0  
Component:  Admin interface     |     Version:  SVN       
 Keywords:  ModelAdmin,Manager  |       Stage:  Unreviewed
Has_patch:  1                   |  
--------------------------------+-------------------------------------------
 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:

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8806>
Django Code <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