File: validators.rst

package info (click to toggle)
python-django-extensions 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,820 kB
  • sloc: python: 18,601; javascript: 7,354; makefile: 108; xml: 17
file content (35 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Validators
==========

:synopsis: Validator extensions

Usage
-----

Example::

    from django_extensions.validators import HexValidator

    class UserKeys(models.Model):
        user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

        public_key = models.CharField(max_length=64, validators=[HexValidator(length=64)])
        private_key = models.CharField(max_length=128, validators=[HexValidator(length=128)])


Current Database Model Field Extensions
---------------------------------------

``NoControlCharactersValidator``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Validates that Control Characters like new lines or tabs are not allowed.
Can optionally specify `whitelist` of control characters to allow.

``NoWhitespaceValidator``
~~~~~~~~~~~~~~~~~~~~~~~~~
Validates that leading and trailing whitespace is not allowed.

``HexValidator``
~~~~~~~~~~~~~~~~
Validates that the string is a valid hex string.
Can optionally also specify `length`, `min_length` and `max_length` parameters.