def post(self, request): serializer = UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() logger.info(f"User {serializer.data.get('username')} is created") return Response(serializer.data) logger.error(f"User creation failed: {serializer.errors}") return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class TaskDocumentSerializer(serializers.ModelSerializer): creator = UserSerializer(read_only=True) task = TaskSerializer(read_only=True) class Meta: model = TaskDocument fields = '__all__'
class TaskSerializer(serializers.ModelSerializer): creator = UserSerializer(read_only=True) block = BlockListSerializer(read_only=True) class Meta: model = Task fields = '__all__'
class ProjectDetailedSerializer(ProjectListSerializer): creator = UserSerializer() class Meta: model = Project fields = ('id', 'name', 'description', 'status_name', 'project_type_name', 'creator')
class TaskCreateSerializer(serializers.ModelSerializer): priority = serializers.IntegerField() creator = UserSerializer(read_only=True) block = BlockListSerializer(read_only=True) class Meta: model = Task fields = '__all__' def validate_priority(self, value): if value > 10 or value < 1: raise serializers.ValidationError('Task priority can be between 1 and 10') return value
class ProjectCreateSerializer(serializers.ModelSerializer): status = serializers.IntegerField() project_type = serializers.IntegerField() creator = UserSerializer(read_only=True) class Meta: model = Project fields = '__all__' def validate_status(self, value): if value > 3 or value < 1: raise serializers.ValidationError('Status options: [1, 2, 3]') return value def validate_project_type(self, value): if value > 2 or value < 1: raise serializers.ValidationError('Project type options: [1, 2]') return value
def post(self, request): serializer = UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class ProjectDetailedSerializer(serializers.ModelSerializer): creator = UserSerializer() class Meta: model = Project fields = '__all__'
def list(self, request, *args, **kwargs): user = self.request.user serializer = UserSerializer(user) return Response(serializer.data)
class TaskDocumentSerializer(serializers.Serializer): creator = UserSerializer(read_only=True) task = TaskSerializer(read_only=True) document = serializers.FileField()