MCPcopy
hub / github.com/django/django / get_field_queryset

Method get_field_queryset

django/contrib/admin/options.py:297–313  ·  view source on GitHub ↗

If the ModelAdmin specifies ordering, the queryset should respect that ordering. Otherwise don't specify the queryset, let the field decide (return None in that case).

(self, db, db_field, request)

Source from the content-addressed store, hash-verified

295 return db_field.formfield(**kwargs)
296
297 def get_field_queryset(self, db, db_field, request):
298 """
299 If the ModelAdmin specifies ordering, the queryset should respect that
300 ordering. Otherwise don't specify the queryset, let the field decide
301 (return None in that case).
302 """
303 try:
304 related_admin = self.admin_site.get_model_admin(db_field.remote_field.model)
305 except NotRegistered:
306 return None
307 else:
308 ordering = related_admin.get_ordering(request)
309 if ordering is not None and ordering != ():
310 return db_field.remote_field.model._default_manager.using(db).order_by(
311 *ordering
312 )
313 return None
314
315 def formfield_for_foreignkey(self, db_field, request, **kwargs):
316 """

Callers 2

Calls 4

get_model_adminMethod · 0.80
order_byMethod · 0.80
get_orderingMethod · 0.45
usingMethod · 0.45

Tested by

no test coverage detected