Beispiel #1
0
class UserSchema(PublicBaseSchema):

    date_joined = fields.DateTime(dump_only=True)
    email = fields.Str(validate=validate.Email())
    first_name = fields.Str(validate=validate.Length(min=1, max=32))
    last_name = fields.Str(validate=validate.Length(min=1, max=32))
    password = fields.Str(load_only=True, validate=validate.Length(min=8))
Beispiel #2
0
class EventSchema(PublicBaseSchema):

    title = fields.Str(validate=validate.Length(max=40), required=True)
    description = fields.Str(validate=validate.Length(max=1000))
    place = fields.Str(validate=validate.Length(max=128))
    date = fields.DateTime(validate=FutureDateValidator(), required=True)
    status = fields.Str(validate=validate.Length(max=32), dump_only=True)
    participants = fields.Method("get_participants")

    def get_participants(self, obj):
        return ParticipantSchema(obj.participants.all(), many=True).data
class TwittersSchema(BaseSchema):
    tweetdate = fields.DateTime()
    nick = fields.String(
        required=True,
        validate=[validate.Length(min=3, max=15)],
    )
    tweet = fields.String(
        required=True,
        validate=[validate.Length(min=0, max=50)],
    )

    def create(self, validated_data):
        return Twitters.objects.create(**validated_data)
Beispiel #4
0
class CrossProductSerializer(Schema):
    id = fields.Integer(read_only=True)
    created = fields.DateTime(read_only=True)
    vector1 = fields.List(fields.Number(),
                          validate=validate.Length(equal=3),
                          required=True)
    vector2 = fields.List(fields.Number(),
                          validate=validate.Length(equal=3),
                          required=True)
    result = fields.List(fields.Number(),
                         validate=validate.Length(equal=3),
                         read_only=True)

    def create(self, data):
        result = CrossProductResult.create(data['vector1'], data['vector2'])
        result.save()

        return result
class BaseSchema(Schema):
    id = fields.Integer()
    removed = fields.Boolean()
    created_date = fields.DateTime()
Beispiel #6
0
class AbstractBaseSchema(Schema):

    created_at = fields.DateTime(dump_only=True)
    updated_at = fields.DateTime(dump_only=True)