django-rest-polymorphic
django-rest-polymorphic copied to clipboard
Disable resourcetype?
Hi guys,
Very good work, I just have one query regarding this. Basically, when I get (Response.data).keys() it is really important for me to receive only attributes defined in within the model. However, I do also get resourcetype. Is there a way to disable that? I do not want to be receiving resourcetype as a parameter at all. I tried all that was in the readme, but nothing worked so far.
Any help?
You can do it by changing the to_representation() function:
def to_representation(self, instance):
if isinstance(instance, Mapping):
resource_type = self._get_resource_type_from_mapping(instance)
serializer = self._get_serializer_from_resource_type(resource_type)
else:
resource_type = self.to_resource_type(instance)
serializer = self._get_serializer_from_model_or_instance(instance)
ret = serializer.to_representation(instance)
# ret[self.resource_type_field_name] = resource_type //Comment out this line
return ret
I didn't test it out, but it should be ok.