Here are my models:
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)
I an trying to get features and feature details of the current phone and loop over data pairs but unable to do so.
I tried this and it only works for getting the brand:
p = get_object_or_404(Phone.objects.select_related('brand', 'feature__featuredetail'), id=id)
And when doing:
print p.featuredetail_set.all()
I get and this error:
Django Version: 1.4.3
Exception Type: AttributeError
Exception Value:
'Phone' object has no attribute 'featuredetail_set'
What's wrong?