In my Django model, I have 10 fields, and there are 3 fields that are foreign keys. In my JSON data obtained from a GET request, I get all fields, but not foreign keys.
I also did this, but I still do not get these fields in JSON data:
DataFields = MyData._meta.get_all_field_names() class MyResource(ModelResource): class Meta: queryset = MyData.objects.all() resource_name = 'Myres' serializer = Serializer(formats=['json']) filtering = dict(zip(DataFields, [ALL_WITH_RELATIONS for f in DataFields]))
For example, I have a field in a model like city , but this field is not available in the JSON that I get from it.
Is there a way that in JSON I can get city:city__name automatically?
If I do this, then I will get the city, but can I do this without a definition:
def dehydrate(self, bundle): bundle.data["city_name"] = bundle.obj.city__name return bundle
user825904
source share