Ticket #13862: inline_queryset_ordering.diff

File inline_queryset_ordering.diff, 2.4 KB (added by Simon Meers, 14 years ago)
  • django/contrib/admin/options.py

     
    6767    prepopulated_fields = {}
    6868    formfield_overrides = {}
    6969    readonly_fields = ()
     70    ordering = None
    7071
    7172    def __init__(self):
    7273        overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy()
     
    183184    def get_readonly_fields(self, request, obj=None):
    184185        return self.readonly_fields
    185186
     187    def queryset(self, request):
     188        """
     189        Returns a QuerySet of all model instances that can be edited by the
     190        admin site. This is used by changelist_view.
     191        """
     192        qs = self.model._default_manager.get_query_set()
     193        # TODO: this should be handled by some parameter to the ChangeList.
     194        ordering = self.ordering or () # otherwise we might try to *None, which is bad ;)
     195        if ordering:
     196            qs = qs.order_by(*ordering)
     197        return qs
     198
    186199class ModelAdmin(BaseModelAdmin):
    187200    "Encapsulates all admin options and functionality for a given model."
    188201
     
    196209    date_hierarchy = None
    197210    save_as = False
    198211    save_on_top = False
    199     ordering = None
    200212    inlines = []
    201213
    202214    # Custom templates (designed to be over-ridden in subclasses)
     
    319331            'delete': self.has_delete_permission(request),
    320332        }
    321333
    322     def queryset(self, request):
    323         """
    324         Returns a QuerySet of all model instances that can be edited by the
    325         admin site. This is used by changelist_view.
    326         """
    327         qs = self.model._default_manager.get_query_set()
    328         # TODO: this should be handled by some parameter to the ChangeList.
    329         ordering = self.ordering or () # otherwise we might try to *None, which is bad ;)
    330         if ordering:
    331             qs = qs.order_by(*ordering)
    332         return qs
    333 
    334334    def get_fieldsets(self, request, obj=None):
    335335        "Hook for specifying fieldsets for the add form."
    336336        if self.declared_fieldsets:
     
    12701270        fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
    12711271        return [(None, {'fields': fields})]
    12721272
    1273     def queryset(self, request):
    1274         return self.model._default_manager.all()
    1275 
    12761273class StackedInline(InlineModelAdmin):
    12771274    template = 'admin/edit_inline/stacked.html'
    12781275
Back to Top