Модель со связью один ко многим class Categories models Model category

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#Модель со связью один ко многим
class Categories(models.Model):
category_name = models.CharField(max_length=30)
category_description = models.CharField(max_length=100)
class Accessories(models.Model):
type = models.ForeignKey(Categories)
model = models.CharField(max_length=100)
short_description = models.TextField()
## Первый вариант
Accessory = Accessories.get(model__exact=some_model)
category_desk = Accessory.type.category_description
##Воторой вариант
for Accessory in Accessories.values('type').distinct():
print Accessory.type.category_description