1👍
✅
You can’t override ModelAdmin.get_queryset()
because it is used in the edit/delete views. So you have to inherit ChangeList
class and override get_queryset()
in it:
from django.contrib import messages
from django.contrib.admin.views.main import ChangeList
class MyChangeList(ChangeList):
def get_queryset(self, request):
queryset = super(MyChangeList, self).get_queryset(request)
if not request.GET.get('q', ''):
messages.add_message(request, messages.INFO, 'Start typing.')
queryset = queryset.none()
return queryset
class MyAdmin(admin.ModelAdmin):
def get_changelist(self, request, **kwargs):
return MyChangeList
Source:stackexchange.com