Codesnippet.dev
</>

Django - How to override Meta class

Problem statement

Sometimes you need to extend a class in Django and you'd like to override it's Meta class. Typical example is if you have Django REST Framework serializer and you'd like to extend detail serializer and base it on top of other serializer.

Solution

class JobDetailSerializer(JobSerializer):
class Meta(JobSerializer.Meta):
fields = JobSerializer.Meta.fields + ('detail_only_property',)