I have this code:
class UserListView(PermissionRequiredMixin, ListView):
permission_required = 'account.view_user'
model = Profile
template_name = 'dashboard/user_list.html'
paginate_by = 20
ordering = '-id'
def post(self, request, *args, **kwargs):
if 'delete' in request.POST.getlist('action'):
selected_ids = request.POST.getlist('user-checkbox')
User.objects.filter(pk__in=selected_ids).delete()
messages.success(request, 'Success')
return render(request, self.template_name, self.get_context_data())
def get_queryset(self):
users = self.model.objects.filter(user__is_superuser=False)
if self.request.method == 'GET' and (q := self.request.GET.get('q')) is not None:
users = users.filter(
Q(first_name__icontains=q) |
Q(last_name__icontains=q) |
Q(user__username__icontains=q)
)
return users
I didn’t change the value of context_object_name
and by default it is the same as object_list
, but when I send a post request to the page, I get this error