我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用django.core.validators.MinLengthValidator()。
def __init__(self, *args, **kwargs): try: self.model_field = kwargs.pop('model_field') except KeyError: raise ValueError("ModelField requires 'model_field' kwarg") self.min_length = kwargs.pop('min_length', getattr(self.model_field, 'min_length', None)) self.max_length = kwargs.pop('max_length', getattr(self.model_field, 'max_length', None)) self.min_value = kwargs.pop('min_value', getattr(self.model_field, 'min_value', None)) self.max_value = kwargs.pop('max_value', getattr(self.model_field, 'max_value', None)) super(ModelField, self).__init__(*args, **kwargs) if self.min_length is not None: self.validators.append(validators.MinLengthValidator(self.min_length)) if self.max_length is not None: self.validators.append(validators.MaxLengthValidator(self.max_length)) if self.min_value is not None: self.validators.append(validators.MinValueValidator(self.min_value)) if self.max_value is not None: self.validators.append(validators.MaxValueValidator(self.max_value))
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs): self.max_length = max_length self.min_length = min_length self.strip = strip super(CharField, self).__init__(*args, **kwargs) if min_length is not None: self.validators.append(validators.MinLengthValidator(int(min_length))) if max_length is not None: self.validators.append(validators.MaxLengthValidator(int(max_length)))
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs): self.max_length = max_length self.min_length = min_length self.strip = strip self.empty_value = empty_value super(CharField, self).__init__(*args, **kwargs) if min_length is not None: self.validators.append(validators.MinLengthValidator(int(min_length))) if max_length is not None: self.validators.append(validators.MaxLengthValidator(int(max_length)))
def __init__(self, *args, min_length=10, **kwargs): kwargs.setdefault('max_length', 14) if min_length < 10: self.min_length = 10 else: self.min_length = min_length if kwargs['max_length'] < self.min_length: kwargs['max_length'] = self.min_length super(ModelPhoneField, self).__init__(*args, **kwargs) self.validators.append(validators.MinLengthValidator(self.min_length))
def __init__(self, *args, **kwargs): if "max_length" not in kwargs: kwargs["max_length"] = 13 if "validators" not in kwargs: kwargs["validators"] = [validators.MinLengthValidator(12), validators.RegexValidator(r"\d{2}:\d{2}:\d{6,7}")] super(CadastralBlockTypeField, self).__init__(*args, **kwargs)
def __init__(self, max_length=None, min_length=None, *args, **kwargs): self.max_length, self.min_length = max_length, min_length super(CharField, self).__init__(*args, **kwargs) if min_length is not None: self.validators.append(validators.MinLengthValidator(int(min_length))) if max_length is not None: self.validators.append(validators.MaxLengthValidator(int(max_length)))
def __init__(self, max_length=None, min_length=None, allow_none=False, *args, **kwargs): self.max_length, self.min_length = max_length, min_length self.allow_none = allow_none super(CharField, self).__init__(*args, **kwargs) if min_length is not None: self.validators.append(validators.MinLengthValidator(min_length)) if max_length is not None: self.validators.append(validators.MaxLengthValidator(max_length))
def __init__(self, *args, **kwargs): self.min_length = 6 self.max_length = 32 kwargs["max_length"] = kwargs.get("max_length", self.max_length) super().__init__(*args, **kwargs) self.validators.append(MinLengthValidator(self.min_length)) self.validators.append(MaxLengthValidator(self.max_length))
def __init__(self, *args, **kwargs): self.min_length = 6 self.max_length = 33 kwargs["max_length"] = kwargs.get("max_length", self.max_length) super().__init__(*args, **kwargs) self.validators.append(MinLengthValidator(self.min_length)) self.validators.append(MaxLengthValidator(self.max_length))