Allow callable queryset in generic views
|Reported by:||raffaele.salmaso@…||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
I need to pass a variable queryset based on some external condition
(i.e. it can be Entry.objects.all() or Entry.objects.filter(...) or other), but with current implementation it is impossible,
because generic views want a queryset, which is set indefinitely (I'm thinking about the use in urls.py, not in
Actually I wrote a simple wrapper, as
def obj_list(request, queryset, ...): if callable(queryset): queryset = queryset() return object_list(request, queryset, ...) ...
and pass a function which returns the queryset I need.
I found it could be useful if it is included directly in the generic views function.
The attached patch adds this functionality, and it doesn't break any previous code.
Change History (4)
Changed 6 years ago by raffaele.salmaso@…
comment:1 Changed 6 years ago by andreas@…
- Needs documentation unset
- Needs tests set
- Patch needs improvement unset
comment:2 Changed 6 years ago by mtredinnick
- Resolution set to wontfix
- Status changed from new to closed