Django模型的对象引用-缺少“对象”

时间:2019-12-07 19:17:47

标签: python django

我的数据如下:
Store Count_Customers Count_Purchases BestBuy 2 2 Target 1 1 Target 4 3 Walmart 5 1 Target 9 1

我想使用Django模型生成商店列表,并按商店汇总。

所以我有models.py作为:

class UniqueStore(models.Model):
    store = models.CharField(db_column='store', max_length=100, unique=True)


class Summarize(object):
    store = models.ForeignKey(UniqueStore,
                             on_delete=models.CASCADE, unique=True) 
    sum_customers = models.IntegerField(u"count_customers") 
    sum_purchases = models.IntegerField(u"count_purchases")

和my_summary.py作为管理命令,

class Command(BaseCommand):
    help = "Summary by store"

    def handle(self, *args, **options):
        print("Stores: {}".format(UniqueStore.objects.all().count()))
        print("Facts: {}".format(Summarize.objects.all().sum()))

但是即使在运行python manage.py my_summary之前,我仍然收到错误unresolved attribute reference: object

可以帮助我了解如何解决此错误吗?

我没有在文档https://docs.djangoproject.com/en/3.0/topics/db/models/

中解决此问题

如果与元类(django model referencing object from other class)有关,有人可以提供其他资源/解释吗?

1 个答案:

答案 0 :(得分:1)

摘要是对象类型,但必须是模型类型。