我试图在 Django 中表示一种混合物。就像是:
Chemical #1 - 50%
Chemical #2 - 30%
Chemical #3 - 20%
我想我会使用一个名为 composition 的包装器,如下所示:
class Composition(models.Model):
""" Just a Wrapper """
def save(...):
#Validate ingredients add up to 100% and such
class Ingredient(models.Model):
composition = models.ForeignKey('Composition',related_name='ingredients')
name = models.CharField(max_length = 10)
percentage = models.IntegerField()
我很确定有更好的方法来做到这一点。请记住,我这样做是为了以后可以在 Django 管理员中使用内联。大家有什么推荐的?非常感谢 =)