2017-04-25 140 views
0

間接的關係,我有三個型號Django的關係如何映射模型

class Venue(models.Model): 
    property_values = models.ManyToManyField('feature.PropertyValue') 

class Feature(models.Model): 
    name = models.CharField(max_length=255, null=False, blank=False) 

class PropertyValue(models.Model): 
    name = models.CharField(max_length=255, null=False, blank=False) 
    feature = models.ForeignKey('Feature', null=False, blank=False) 

在此我希望能夠在通過屬性值屬於它的場地模型俗話說配置「功能」。

class Venue(models.Model): 
    property_values = models.ManyToManyField('feature.PropertyValue') 
    feature = models.ManyToManyField(via property_value something) 

回答

0

你已經用上了通過property_values

one = Venue.objects.first() 
one.property_vaues.all()[0].feature