Reputation: 45
from django.contrib.auth.models import User
...
class FruitList(ListView):
model = Fruit
paginate_by = "2"
queryset = Fruit.objects.filter(user=request.user)
context_object_name = "myfruitlist"
template_name = 'myfruit_list.html'
Error:
name 'request' is not defined
How can I fix it?
Upvotes: 1
Views: 1977
Reputation: 668
You have to access it this way:
def get_queryset(self):
return Fruit.objects.filter(user=self.request.user)
You can read about this here in docs
Upvotes: 3