Python 如何在外键Django中获取计数项?
我有两类模型,我需要从一个供应商那里获得产品的数量Python 如何在外键Django中获取计数项?,python,django,Python,Django,我有两类模型,我需要从一个供应商那里获得产品的数量 class Vendor(models.Model): name = models.CharField(max_length=50, unique=True) seo_name = models.SlugField() product_count = models.IntegerField(default=0) class Product(models.Model): vendor = mod
class Vendor(models.Model):
name = models.CharField(max_length=50, unique=True)
seo_name = models.SlugField()
product_count = models.IntegerField(default=0)
class Product(models.Model):
vendor = models.ForeignKey(Vendor, unique=False, blank=True, default=None, null=True, on_delete=models.SET_NULL)
如何计算供应商中的产品数量?请查看本教程。它完全涵盖了你的问题
祝你好运 谢谢!祝你也好运:)