类'Item'没有'Objects'memberpylint(no-member)

时间:2019-09-10 12:46:34

标签: python django

我试图将模型导入到我的视图中,但是以某种方式给我一个错误“类'Item'没有'对象'memberpylint(no-member)”。我不明白为什么?

views.py

from django.shortcuts import render
from .models import Item

# def products(request):
#     context = {
#         'items': Item.objects.all()
#     }
#     return render(request, "products.html", context)

def item_list(request):
    context = {
        'items': Item.Objects.all()
    }
    return render(request, "home-page.html", context)

def checkout(request):
    return render(request, "checkout.html")

这是我的模型

from django.conf import settings
from django.db import models

CATEGORY_CHOICES = (
    ('S', 'Shirt'),
    ('SW', 'Sportswear'),
    ('OW', 'Outwear')
)

LABEL_CHOICES = (
    ('P', 'primary'),
    ('S', 'secondary'),
    ('D', 'danger')
)

class Item(models.Model):
    title = models.CharField(max_length = 100)
    price = models.FloatField()
    category = models.CharField(choices=CATEGORY_CHOICES, max_length=2)
    label = models.CharField(choices=LABEL_CHOICES, max_length=1)

    def _str_(self):
        return self.title

class OrderItem(models.Model):
    item = models.ForeignKey(Item, on_delete=models.CASCADE)
    title = models.CharField(max_length = 100)
    def _str_(self):
        return self.title


class Order(models.Model):
    title = models.CharField(max_length = 100)
    items = models.ManyToManyField(OrderItem)
    start_date = models.DateTimeField(auto_now_add=True)
    ordered_date = models.DateTimeField()
    ordered = models.BooleanField(default=False)

    def _str_(self):
        return self.title

谁能告诉我我做错了什么吗?

当我尝试调用Item时,它与product函数相同,这给了我同样的错误。这就是为什么我发表评论。

1 个答案:

答案 0 :(得分:0)

请尝试使用特定于Django的Pylint plugin,我认为这可以解决您的问题。