1

我们可以让外键模型字段在另一个模型中显示为 django 管理站点上的字段(而不是列表显示)。我有一个具有 Price 外键的产品和价格模型。我想在 Product 和 Variation 模型中将 price、sale_price 和 sale 显示为可编辑字段。

class Price(models.Model):
    price = models.DecimalField(decimal_places=2, max_digits=8)
    sale_price = models.DecimalField(decimal_places=2, max_digits=8)
    sale = models.BooleanField(default=False)

class Product(models.Model):
    title = models.CharField(max_length=120)
    description = models.TextField(blank=True, null=True)
    price =  models.ForeignKey('Price')

class Variation(models.Model):
    product = models.ForeignKey(Product)
    price =  models.ForeignKey('Price')
    title = models.CharField(max_length=120)
4

1 回答 1

2

您可以使用 admin 内联。 https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#inlinemodeladmin-objects

于 2016-07-19T22:50:56.013 回答