ModelAdmin.queryset() internal documentation
|Reported by:||Keryn Knight <kez.knight@…>||Owned by:||nobody|
|Severity:||Keywords:||queryset modeladmin documentation|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Part of this may tie into #10712 which is an attempt to provide userland documentation for ModelAdmin methods. Currently, the internal docstring for ModelAdmin.queryset() reads as follows:
""" Returns a QuerySet of all model instances that can be edited by the admin site. This is used by changelist_view. """
The implication seems to be that its only called by the changelist. In certain circumstances, it may be useful to override what's displayed in the changelist - this is part of what #10712 attempts to address. Modifying the queryset method (and by extension ChangeList) actually affects the queryset used by the entire modeladmin, which means one cannot navigate to an edit object not in the modified queryset.
I concede that this is currently by design, and is in most cases the expected (and desired) behaviour. Certain circumstances may facilitate changing this default, which currently involves generating two ChangeList objects in the changelist_view() method and using context precedence to get rid of the original.
As I see it, there are three options. The simplest is obviously to ignore this as by design and wontfix. Another is to expand the docstring to explain in more detail its overall role in the modeladmin (which may mean changing #10712 further). The hardest (and best, in my opinion) option is, I think, mostly put forward by #10761 - have multiple methods we can easily modify in userland, defaulting back to queryset() if they're not provided, perhaps.