def convert_field(self, name, field):
        """
        Convert a single field from a Peewee model field to a validator field.

        :param name: Name of the field as defined on this validator.
        :param name: Peewee field instance.
        :return: Validator field.
        """
        if PEEWEE3:
            field_type = field.field_type.lower()
        else:
            field_type = field.db_field

        pwv_field = ModelValidator.FIELD_MAP.get(field_type, StringField)

        print('pwv_field', field_type, pwv_field)

        validators = []
        required = not bool(getattr(field, 'null', True))
        choices = getattr(field, 'choices', ())
        default = getattr(field, 'default', None)
        max_length = getattr(field, 'max_length', None)
        unique = getattr(field, 'unique', False)

        if required:
            validators.append(validate_required())

        if choices:
            print('CHOICES', choices)
            validators.append(validate_one_of([c[0] for c in choices]))

        if max_length:
            validators.append(validate_length(high=max_length))

        if unique:
            validators.append(validate_model_unique(field, self.instance.select(), self.pk_field, self.pk_value))

        if isinstance(field, peewee.ForeignKeyField):
            if PEEWEE3:
                rel_field = field.rel_field
            else:
                rel_field = field.to_field
            return ModelChoiceField(field.rel_model, rel_field, default=default, validators=validators)

        if isinstance(field, ManyToManyField):
            return ManyModelChoiceField(
                field.rel_model, field.rel_model._meta.primary_key,
                default=default, validators=validators)

        return pwv_field(default=default, validators=validators)
def convert_field ( self , name , field ) : if PEEWEE3 : field_type = field . field_type . lower ( ) else : field_type = field . db_field pwv_field = ModelValidator . FIELD_MAP . get ( field_type , StringField ) print ( 'pwv_field' , field_type , pwv_field ) validators = [ ] required = not bool ( getattr ( field , 'null' , True ) ) choices = getattr ( field , 'choices' , ( ) ) default = getattr ( field , 'default' , None ) max_length = getattr ( field , 'max_length' , None ) unique = getattr ( field , 'unique' , False ) if required : validators . append ( validate_required ( ) ) if choices : print ( 'CHOICES' , choices ) validators . append ( validate_one_of ( [ c [ 0 ] for c in choices ] ) ) if max_length : validators . append ( validate_length ( high = max_length ) ) if unique : validators . append ( validate_model_unique ( field , self . instance . select ( ) , self . pk_field , self . pk_value ) ) if isinstance ( field , peewee . ForeignKeyField ) : if PEEWEE3 : rel_field = field . rel_field else : rel_field = field . to_field return ModelChoiceField ( field . rel_model , rel_field , default = default , validators = validators ) if isinstance ( field , ManyToManyField ) : return ManyModelChoiceField ( field . rel_model , field . rel_model . _meta . primary_key , default = default , validators = validators ) return pwv_field ( default = default , validators = validators )
Convert a single field from a Peewee model field to a validator field.

        :param name: Name of the field as defined on this validator.
        :param name: Peewee field instance.
        :return: Validator field.