通过连接的方式访问模型字段

时间:2018-01-28 01:40:07

标签: python django django-models django-2.0

我有两个型号

class Category(models.Model):
    name = models.CharField("category", max_length=200, null=True)
    discount = models.PositiveIntegerField(null=True)

class Product(models.Model):
    name = models.CharField("product", max_length=200)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="products", verbose_name="category")

如何在管理面板中显示discount值?

class ProductAdmin(admin.ModelAdmin):
    list_display = ['name', 'category', 'price', 'discount'] # not works
    list_filter = ['category', 'price']
    list_editable = ['price']

1 个答案:

答案 0 :(得分:0)

这是解决方案:

ggplot() + geom_line(aes(color=variable, x=x, y=value), data=df.m)