You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
586 B

  1. from rest_framework import serializers
  2. from .models import Member
  3. class MemberSerializer(serializers.ModelSerializer):
  4. username = serializers.SerializerMethodField()
  5. rolename = serializers.SerializerMethodField()
  6. @classmethod
  7. def get_username(cls, instance):
  8. user = instance.user
  9. return user.username if user else None
  10. @classmethod
  11. def get_rolename(cls, instance):
  12. role = instance.role
  13. return role.name if role else None
  14. class Meta:
  15. model = Member
  16. fields = ('id', 'user', 'role', 'username', 'rolename')