Reputation: 381
template code
<html>
<head>
<meta charset="utf-8">
<title>Customer Page</title>
</head>
<body>
<h1>Dear user, please check if the the email list is correct</h1>
<ul>
{% for customer in customer_list.objects.all %}
<li>{{customer.Country}}</li>
{% endfor %}
</ul>
</body>
</html>
view code
from practice.models import Customer
class CustomersView(ListView):
template_name = "practice/customer_list.html"
context_object_name = "customer_list"
def get_queryset(self):
return Customer.objects.all()
However, in the code above, pylint underlined Customer and stated "Class 'Customer' has no 'objects' member"
The browser only shows this
In [1]: from practice.models import Customer
In [2]: Customer.objects.all()
Out[2]: <QuerySet [<Customer: Customer object (1)>, <Customer: Customer object (2)>]>
What might be the possible causes?
Upvotes: 0
Views: 28
Reputation: 675
first of all remove the get_queryset
method and instead define attribute model=Customer
- that's the proper way to work with ListView
. In your case the get_queryset
override is redundant because you rewrite it exactly as it is when you define model for your ListVeiw
. Then as the other commented said use {% for customer in customer_list %}
Upvotes: 1
Reputation: 1466
change {% for customer in customer_list.objects.all %}
for {% for customer in customer_list %}
Upvotes: 2