我有链式模型->类别-品牌-类型。 例如:
我有一个邮政模型。 问题:如何获取表格中的链接对象? 代码:
class Category(models.Model):
title = models.CharField(max_length=32)
slug = models.SlugField(max_length=32)
def __str__(self):
return "%s" % self.title
class Brand(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
title = models.CharField(max_length=32)
def __str__(self):
return "%s" % self.title
class Type(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
brand = ChainedForeignKey(
'Brand',
chained_field="category",
chained_model_field="category",
show_all=False,
auto_choose=True
)
title = models.CharField('Модель автомобіля', max_length=32)
slug = models.SlugField(max_length=32)
def __str__(self):
return "%s" % self.title
发布模型:
class Post(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
type = models.ForeignKey(Type, on_delete=models.CASCADE)
......
def __str__(self):
return "{} {}".format(self.brand, self.type)
我需要创建一个带有链接对象的表单。我如何得到它?或如何编辑我的帖子模型?