У меня есть две модели:
class Categories(models.Model):
name_ru = models.TextField(null=True)
name_kz = models.TextField(null=True)
name_en = models.TextField(null=True)
def __str__(self):
return self.name_ru
class Meta:
db_table = 'categories'
class Theme(models.Model):
name = models.TextField(null = False)
category = models.ForeignKey(Categories,on_delete=models.CASCADE, null = False)
class Meta:
db_table = 'theme'
serializers.py
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Categories
fields = ('__all__')
class ThemeSerializer(serializers.ModelSerializer):
qs = Categories.objects.all()
category = serializers.PrimaryKeyRelatedField(queryset=qs)
class Meta:
model = Theme
fields = ('id', 'name', 'category')
Сейчас мне возвращает такой ответ:
{
"type": "Theme",
"id": "3",
"attributes": {
"name": "******"
},
"relationships": {
"category": {
"data": {
"type": "Categories",
"id": "2"
}
}
}
},
А нужно чтобы было так:
{
"type": "Theme",
"id": "3",
"attributes": {
"name": "***"
},
"relationships": {
"category": {
"data": {
"type": "Categories",
"id": "2"
"name_ru": "Политика",
"name_kz": "Саясат",
"name_en": "Politics"
}
}
}
}
},