LilyFoote/rest-framework-generic-relations

Including Types question

daxaxelrod opened this issue · 0 comments

Hi, Thanks for this lib! I'd like my frontend to have a bit more context as to what type of component to render and would like to include the model type when serializing.

To accomplish this, I've modified the to_representaion method.

class GenericRelatedFieldWithType(GenericRelatedField):
    def to_representation(self, instance):
        data = super(GenericRelatedFieldWithType, self).to_representation(instance)
        data.update({"type": self.Meta.model.__name__})
        return data

Is this how you would do the same and would it be something that this lib would accept a PR for (an additional include_type=True|False)?

Thanks!