I am trying to create a view that restricts results based on user authentication. For some reason, cutting lists always results in an AssertionError. It is not possible to filter the query after the slice has been done.
class CustomGalleryDetailView(DetailView):
def get_queryset(self):
if not self.request.user.is_authenticated():
return Gallery.objects.on_site().is_public()[:3]
else:
return Gallery.objects.on_site().is_public()
Even when i try
return Gallery.objects.all()[:3],
Without further filtering, I still get the same error.
source
share