Ticket #13862: inline_queryset_ordering.diff
File inline_queryset_ordering.diff, 2.4 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/options.py
67 67 prepopulated_fields = {} 68 68 formfield_overrides = {} 69 69 readonly_fields = () 70 ordering = None 70 71 71 72 def __init__(self): 72 73 overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy() … … 183 184 def get_readonly_fields(self, request, obj=None): 184 185 return self.readonly_fields 185 186 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 186 199 class ModelAdmin(BaseModelAdmin): 187 200 "Encapsulates all admin options and functionality for a given model." 188 201 … … 196 209 date_hierarchy = None 197 210 save_as = False 198 211 save_on_top = False 199 ordering = None200 212 inlines = [] 201 213 202 214 # Custom templates (designed to be over-ridden in subclasses) … … 319 331 'delete': self.has_delete_permission(request), 320 332 } 321 333 322 def queryset(self, request):323 """324 Returns a QuerySet of all model instances that can be edited by the325 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 qs333 334 334 def get_fieldsets(self, request, obj=None): 335 335 "Hook for specifying fieldsets for the add form." 336 336 if self.declared_fieldsets: … … 1270 1270 fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj)) 1271 1271 return [(None, {'fields': fields})] 1272 1272 1273 def queryset(self, request):1274 return self.model._default_manager.all()1275 1276 1273 class StackedInline(InlineModelAdmin): 1277 1274 template = 'admin/edit_inline/stacked.html' 1278 1275