Hi i want to provide only pair of values without keys on REST service:
take a look on my serializers.py:
class TranslationSerializer(serializers.ModelSerializer):
translated_term = serializers.CharField(read_only=True)
class Meta:
model = Translation
fields = ('language','translated_term')
class VocabSerializer(serializers.ModelSerializer):
...
translates = TranslationSerializer(many=True, read_only=True)
...
class Meta:
model = Vocab
fields = ( ..., 'translates',...)
The result is the following:
"translates": [
{
"language": "EN",
"translated_term": "Chair"
}
{
"language": "IT",
"translated_term": "asd"
}
],
as you can see this result shows the name of the field as dict key next to the value of that field. but i would like to have a different structure. Like the following:
"translates": [
{
"EN": "Chair", "IT":"asd"
}
],
this example shows a pair of key/value where key is the language field value and the value of dict is the value of translated field.
How can i show only the pair of values of 'language' field with 'translated' field without the name of field?