这是我的模型:
class Brand(models.Model):
name = models.CharField(max_length=30)
order = models.SmallIntegerField()
class FeatureGroup(models.Model):
name = models.CharField(max_length=30)
class Feature(models.Model):
name = models.CharField(max_length=30, blank=True)
order = models.SmallIntegerField()
group = models.ForeignKey(FeatureGroup)
class FeatureDetail(models.Model):
description = models.TextField()
feature = models.ForeignKey(Feature)
class Phone(models.Model):
name = models.CharField(max_length=30)
brand = models.ForeignKey(Brand)
features = models.ManyToManyField(FeatureDetail)
我试图获取当前手机的功能和功能详细信息并循环数据对但无法这样做。
我试过这个,它只适用于获得品牌:
p = get_object_or_404(Phone.objects.select_related('brand', 'feature__featuredetail'), id=id)
做的时候:
print p.featuredetail_set.all()
我得到了这个错误:
Django Version: 1.4.3
Exception Type: AttributeError
Exception Value:
'Phone' object has no attribute 'featuredetail_set'
怎么了?