backend/app/users/api/serializers.py

36 lines
924 B
Python
Raw Normal View History

from rest_framework import serializers
2022-10-08 17:14:19 +03:00
from ..service import create_season
from users.models import User
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = [
"about",
"name",
"type",
"telegram",
"password",
"salary",
"respect",
"wallet_public_key",
]
extra_kwargs = {
"password": {"write_only": True},
"wallet_public_key": {"read_only": True},
}
def create(self, validated_data):
user = User.objects.create(
**validated_data, username=validated_data["telegram"]
)
return user
2022-10-08 17:14:19 +03:00
class CreateSeasonSerializer(serializers.Serializer):
created = serializers.BooleanField(read_only=True)
def create(self, *args, **kwargs):
create_season()
return {'created': True}