Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created July 22, 2019 20:17
Show Gist options
  • Select an option

  • Save akshar-raaj/980c819ef36adfe6adbd377287036092 to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/980c819ef36adfe6adbd377287036092 to your computer and use it in GitHub Desktop.
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('email', 'first_name', 'last_name')
def to_representation(self, instance):
representation = super().to_representation(instance)
if instance.is_superuser:
representation['admin'] = True
return representation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment