Ticket #7510: options.diff

File options.diff, 1.9 KB (added by jjackson, 16 years ago)

Patch as of rev 8861 or Django 1.0.

  • django/contrib/admin/options.py

     
    235235        opts = self.opts
    236236        return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())
    237237
     238    def manager(self, request):
     239        """
     240        Returns a Manager to be queried in the admin site. This is used by
     241        queryset, changelist_view, and delete_view.
     242        """
     243        if not hasattr(self, 'model_admin_manager'):
     244            self.model_admin_manager = self.model._default_manager
     245        return self.model_admin_manager
     246
    238247    def queryset(self, request):
    239248        """
    240249        Returns a QuerySet of all model instances that can be edited by the
    241250        admin site. This is used by changelist_view.
    242251        """
    243         qs = self.model._default_manager.get_query_set()
     252        qs = self.manager(request).get_query_set()
    244253        # TODO: this should be handled by some parameter to the ChangeList.
    245254        ordering = self.ordering or () # otherwise we might try to *None, which is bad ;)
    246255        if ordering:
     
    554563        app_label = opts.app_label
    555564
    556565        try:
    557             obj = model._default_manager.get(pk=object_id)
     566            obj = self.manager(request).get(pk=object_id)
    558567        except model.DoesNotExist:
    559568            # Don't raise Http404 just yet, because we haven't checked
    560569            # permissions yet. We don't want an unauthenticated user to be able
     
    667676        app_label = opts.app_label
    668677
    669678        try:
    670             obj = self.model._default_manager.get(pk=object_id)
     679            obj = self.manager(request).get(pk=object_id)
    671680        except self.model.DoesNotExist:
    672681            # Don't raise Http404 just yet, because we haven't checked
    673682            # permissions yet. We don't want an unauthenticated user to be able
Back to Top