Custom Lookups

Django offers a wide variety of built-in lookups for filtering (for example, exact and icontains). This documentation explains how to write custom lookups and how to alter the working of existing lookups. For the API references of lookups, see the Lookup API reference. A simple lookup example Let’s start with a simple custom lookup. We will write a custom lookup ne which works opposite to exact. Author.objects.filter(name__ne='Jack') will translate to the SQL: "author"."name" <> 'Jack' T

core.validators.URLValidator.schemes

schemes URL/URI scheme list to validate against. If not provided, the default list is ['http', 'https', 'ftp', 'ftps']. As a reference, the IANA website provides a full list of valid URI schemes.

core.validators.URLValidator

class URLValidator(schemes=None, regex=None, message=None, code=None) [source] A RegexValidator that ensures a value looks like a URL, and raises an error code of 'invalid' if it doesn’t. Loopback addresses and reserved IP spaces are considered valid. Literal IPv6 addresses (RFC 2732) and unicode domains are both supported. In addition to the optional arguments of its parent RegexValidator class, URLValidator accepts an extra optional attribute: schemes URL/URI scheme list to validate aga

core.validators.RegexValidator.regex

regex The regular expression pattern to search for the provided value, or a pre-compiled regular expression. By default, raises a ValidationError with message and code if a match is not found. That standard behavior can be reversed by setting inverse_match to True, in which case the ValidationError is raised when a match is found. By default, matches any string (including an empty string).

core.validators.RegexValidator.message

message The error message used by ValidationError if validation fails. Defaults to "Enter a valid value".

core.validators.RegexValidator.inverse_match

inverse_match The match mode for regex. Defaults to False.

core.validators.RegexValidator.flags

flags The flags used when compiling the regular expression string regex. If regex is a pre-compiled regular expression, and flags is overridden, TypeError is raised. Defaults to 0.

core.validators.RegexValidator.code

code The error code used by ValidationError if validation fails. Defaults to "invalid".

core.validators.RegexValidator

class RegexValidator(regex=None, message=None, code=None, inverse_match=None, flags=0) [source] Parameters: regex – If not None, overrides regex. Can be a regular expression string or a pre-compiled regular expression. message – If not None, overrides message. code – If not None, overrides code. inverse_match – If not None, overrides inverse_match. flags – If not None, overrides flags. In that case, regex must be a regular expression string, or TypeError is raised. regex The regu

core.validators.MinValueValidator

class MinValueValidator(min_value, message=None) [source] Raises a ValidationError with a code of 'min_value' if value is less than min_value.