serializer.py 953 B

1234567891011121314151617181920212223242526272829
  1. from rest_framework import serializers
  2. #from rest_framework.exceptions import ValidationError
  3. #from django.contrib.auth.models import User
  4. from .models import *
  5. from django.contrib.auth.models import *
  6. class UserSerializer(serializers.ModelSerializer):
  7. full_name = serializers.ReadOnlyField()
  8. group_name = serializers.ReadOnlyField(source="groups.name")
  9. class Meta:
  10. model = SharixUser
  11. exclude = ['password', 'id']
  12. read_only_fields = ['username', 'phone_number']
  13. extra_kwargs = {
  14. 'first_name': {'write_only': True},
  15. 'last_name':{'write_only':True}
  16. }
  17. def validate(self, attrs):
  18. return super().validate(attrs)
  19. class GroupToUserSerializer(serializers.ModelSerializer):
  20. class Meta:
  21. model = GroupManager
  22. fields = "__all__"
  23. class GroupSerializer(serializers.ModelSerializer):
  24. class Meta:
  25. model = Group
  26. fields = ("id", "name")