Welcome to Django-CryptographicFields

A package for cryptography in Django, wrapping the Python Pycryptodome library.

Installation

pip install Django-CryptographicFields

Requirements

Settings

INSTALLED_APPS = [
    ...
    'CryptographicFields',
]

CRYPTOGRAPHIC_KEY

Default: None

When value of CRYPTOGRAPHIC_KEY is not None a key will be derived from CRYPTOGRAPHIC_KEY. Otherwise the value will be used for the key will be from SECRET_KEY. While specifiing key make sure that it must contain 50 letters otherwise it will raise an error CryptographicFields.cryptography.LengthError

Filters

List of sort functions provided by CryptographicFields:-

Examples

Cryptography by example

Using symmetrical encryption to store sensitive data in the database.

from django.db import models

from CryptographicFields.fields import *


class User(models.Model):
     uuid = UUIDField()
     username = CharField(max_length=20)
     first_name = CharField(max_length=120)
     last_name = CharField(max_length=120)
     age = SmallIntegerField()
     email = EmailField()
     joined = DateTimeField()

The data will now be automatically encrypted when saved to the database & decrypted when retrived with django’s ORM.CryptographicFields uses an encryption that allows for bi-directional data retrieval.

Generating Data

from .models import User
from uuid import uuid5,NAMESPACE_URL
import datetime

User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.a.random.com"), username="admin", first_name="Albert",
                                     last_name="Frost", age=24, email="albert@gmail.com", joined=datetime.datetime(2015, 12, 26, 18, 35, 54))
User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.b.random.com"), username="empi16", first_name="Empi",
                                     last_name="Tsar", age=16, email="empi@rediff.com", joined=datetime.datetime(2025, 12, 28, 12, 35, 34))
User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.c.random.com"), username="dextEr", first_name="Dexter",
                                     last_name="Flutnes", age=28, email="dextEr@random.com", joined=datetime.datetime(2018, 2, 20, 20, 50, 15))
User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.d.random.com"), username="shahprogrammer", first_name="Dhwanil",
                                     last_name="Shah", age=18, email="shahprogrammer@random.com", joined=datetime.datetime(2018, 4, 1, 20, 25, 14))
User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.e.random.com"), username="graphin", first_name="Graphin",
                                     last_name="frost", age=30, email="graphin@yahoo.com", joined=datetime.datetime(2005, 9, 22, 9, 33, 40))
User.objects.create(uuid=uuid5(NAMESPACE_URL, "https://www.f.random.com"), username="abc", first_name="abc",
                                     last_name="xyz", age=16, email="abc@yahoo.com", joined=datetime.datetime(2009, 7, 22, 14, 5, 40))

Sorting by example

from .models import User
from CryptographicFields.filters import sort,iendswith,startswith

# You can use any method that generate QuerySet object like all,filters etc
queryset=User.objects.all()
"""Sort function takes first arg Queryset second sort_function third field name
fourth your query value & return new QuerySet object with sorted data"""
# using iendswith to sort queryset
sort_queryset=sort(queryset, iendswith, 'username', "er")
print(sort_queryset)
<QuerySet [<User: User object (3)>, <User: User object (4)>]>
# using startswith to sort queryset
sort_queryset=sort(self.queryset, startswith, 'last_name', "F")
print(sort_queryset)
<QuerySet [<User: User object (1)>, <User: User object (3)>]>

Ordering by example

from .models import User
from CryptographicFields.filters import order_by

# You can use any method that generate QuerySet object like all,filters etc
queryset=User.objects.all()
"""Order_by functions takes queryset as first arg &
tuple with fields_name from higher priority to lower priority
For eg in this case highest priority is age & lowest priority is username.
i.e it will sort queryset with username field value if it finds two or more objects with same age value"""
# Ascending Order
order_queryset=(order_by(self.queryset, ("age", "username"))
print(order_queryset)
<QuerySet [<User: User object (6)>, <User: User object (2)>,
 <User: User object (4)>, <User: User object (1)>,
 <User: User object (3)>, <User: User object (5)>]>
# Descending Order
order_queryset=(order_by(self.queryset, ("age", "username"),reverse=True)
print(order_queryset)
<QuerySet [<User: User object (5)>, <User: User object (3)>,
 <User: User object (1)>, <User: User object (4)>,
 <User: User object (2)>, <User: User object (6)>]>

CryptographicFields package

CryptographicFields.cryptography module

exception CryptographicFields.cryptography.LengthError(length)[source]

Bases: Exception

CryptographicFields.cryptography.get_key(settings) → str[source]

Gets the encryption for encrypting & decrypting data.

Gets value from CRYPTOGRAPHIC_KEY & if not defined then from SECRET_KEY Checks the len of the key id less than 50 then raise LengthError

Raises

LengthError – It raises when the len of Encryption is less than 50 chars

Returns

Key for cryptography

Return type

str

CryptographicFields.cryptography.type_check(string) → bytearray[source]

Checks weather the inputed data is in correct format which is required for encryption & decryption.

Checks weather the inputed data is in correct format which is required for encryption & decryption. Which is in this case is bytearray

Parameters

string (Any) – Data from User

Returns

bytes

Return type

bytearray

CryptographicFields.cryptography.to_hex(string) → hex[source]

Converts bytes to hex

Converts the bytes received after encryption to hex for storing it in database

Parameters

string (bytes) – encrypted bytes

Returns

hexify the bytes

Return type

hex

CryptographicFields.cryptography.from_hex(hexstring) → bytearray[source]

converts hex to bytearray

Converts the hex string received from databse to bytes for decryption

Parameters

hexstring (hex) – hex string recieved from database

Returns

bytes from hex string

Return type

bytearray

CryptographicFields.cryptography.encrypt(string) → hex[source]

Encrypts the data

Encrypts the data recieved from user using AES-256 CFB

Parameters

string (Any) – Data from User

Returns

the hex of the encrypted string

Return type

hex

CryptographicFields.cryptography.decrypt(hexstring) → bytearray[source]

Decrypts the data

Decrypts the data recieved from database using AES-256 CFB

Parameters

hexstring (hex) – hex string recieved from database

Returns

bytes of decrypted string

Return type

bytearray

CryptographicFields.fields module

class CryptographicFields.fields.StartsWith(lhs, rhs)[source]

Bases: django.db.models.lookups.FieldGetDbPrepValueMixin, django.db.models.lookups.StartsWith

class CryptographicFields.fields.CharField(*args, **kwargs)[source]

Bases: django.db.models.fields.CharField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.BooleanField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.BooleanField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.DateField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)[source]

Bases: django.db.models.fields.DateField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
pre_save(model_instance, add)[source]

Return field’s value just before saving.

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'date': <class 'CryptographicFields.fields.StartsWith'>, 'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.DateTimeField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)[source]

Bases: django.db.models.fields.DateTimeField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
pre_save(model_instance, add)[source]

Return field’s value just before saving.

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'date': <class 'CryptographicFields.fields.StartsWith'>, 'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.TimeField(verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs)[source]

Bases: django.db.models.fields.TimeField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
pre_save(model_instance, add)[source]

Return field’s value just before saving.

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'time': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.DecimalField(verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs)[source]

Bases: django.db.models.fields.DecimalField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_save(value, connection)[source]

Return field’s value prepared for saving into a database.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class CryptographicFields.fields.EmailField(*args, **kwargs)[source]

Bases: CryptographicFields.fields.CharField

default_validators = [<django.core.validators.EmailValidator object>]
description
formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.FloatField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.FloatField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class CryptographicFields.fields.IntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.IntegerField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class CryptographicFields.fields.BigIntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: CryptographicFields.fields.IntegerField

error_messages
description
MAX_BIGINT = 9223372036854775807
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class CryptographicFields.fields.GenericIPAddressField(verbose_name=None, name=None, protocol='both', unpack_ipv4=False, *args, **kwargs)[source]

Bases: django.db.models.fields.GenericIPAddressField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.PositiveBigIntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.PositiveIntegerRelDbTypeMixin, CryptographicFields.fields.IntegerField

description
error_messages
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class CryptographicFields.fields.PositiveIntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.PositiveIntegerRelDbTypeMixin, CryptographicFields.fields.IntegerField

description
error_messages
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class CryptographicFields.fields.PositiveSmallIntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.PositiveIntegerRelDbTypeMixin, CryptographicFields.fields.IntegerField

description
error_messages
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class CryptographicFields.fields.SlugField(*args, max_length=50, db_index=True, allow_unicode=False, **kwargs)[source]

Bases: CryptographicFields.fields.CharField

description
default_validators = [<django.core.validators.RegexValidator object>]
deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

get_internal_type()[source]
formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.SmallIntegerField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: CryptographicFields.fields.IntegerField

description
class CryptographicFields.fields.TextField(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class 'django.db.models.fields.NOT_PROVIDED'>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text='', db_column=None, db_tablespace=None, auto_created=False, validators=(), error_messages=None)[source]

Bases: django.db.models.fields.TextField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.URLField(verbose_name=None, name=None, **kwargs)[source]

Bases: CryptographicFields.fields.CharField

default_validators = [<django.core.validators.URLValidator object>]
description
deconstruct()[source]

Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

formfield(**kwargs)[source]

Return a django.forms.Field instance for this field.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.BinaryField(*args, **kwargs)[source]

Bases: django.db.models.fields.BinaryField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.UUIDField(verbose_name=None, **kwargs)[source]

Bases: django.db.models.fields.UUIDField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
class CryptographicFields.fields.FilePathField(verbose_name=None, name=None, path='', match=None, recursive=False, allow_files=True, allow_folders=False, **kwargs)[source]

Bases: django.db.models.fields.FilePathField

get_internal_type() → str[source]
to_python(value: Any) → Any[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

get_prep_value(value: Any) → Any[source]

Perform preliminary non-db specific value checks and conversions.

from_db_value(value: Any, expression: Any, connection: Any) → Any[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

class_lookups = {'startswith': <class 'CryptographicFields.fields.StartsWith'>}
clean(value, model_instance)[source]

Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.

CryptographicFields.filters module

CryptographicFields.filters.sort(queryset: django.db.models.query.QuerySet, lookup_function: Callable[[Union[str, int, float, datetime.datetime, datetime.date, datetime.time, Any], str, Any], bool], field_name: str, query: Any) → django.db.models.query.QuerySet[source]

Filters queryset

Filters queryset as per lookup provided by user &query provided by user

Parameters
  • lookup_function (Callable[[Union[str,int,float,datetime,date,time,Any],str,Any],bool]) – Functions that filters the data

  • queryset (QuerySet) – Queryset generated by querying data

  • field_name (str) – Name of the field which is to be filtered

  • query (Any) – Query for filtering the Queryset

Returns

QuerySet with Filtered Data

Return type

QuerySet

CryptographicFields.filters.order_by(queryset: django.db.models.query.QuerySet, field_name: Tuple[str, ], reverse: bool = False) → django.db.models.query.QuerySet[source]

Order Queryset by the given field

Order the Queryset as per field_name given.It supports multiple level of odering

Parameters
  • queryset (QuerySet) – Queryset generated by querying data

  • field_name (Tuple) – Tuple with name of the field from higher priority to lower priority

  • reverse (bool, optional) – Type of ordering (Ascending|Descending), defaults to False

Returns

QuerySet with Ordered Data

Return type

QuerySet

CryptographicFields.filters.startswith(query: str, field_name: str, object: Any) → bool[source]

Check if a string is Starts With the query (Case Sensitive)

CryptographicFields.filters.istartswith(query: str, field_name: str, object: Any) → bool[source]

Check if a string is Starts With the query (Not Case Sensitive)

CryptographicFields.filters.endswith(query: str, field_name: str, object: Any) → bool[source]

Check if a string is Ends With the query (Case Sensitive)

CryptographicFields.filters.iendswith(query: str, field_name: str, object: Any) → bool[source]

Check if a string is Ends With the query (Not Case Sensitive)

CryptographicFields.filters.contains(query: str, field_name: str, object: Any) → bool[source]

Check if query is in value of the object (Case Sensitive)

CryptographicFields.filters.icontains(query: str, field_name: str, object: Any) → bool[source]

Check if query is in value of the object (Not Case Sensitive)

CryptographicFields.filters.gt(query: Union[int, float], field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.gte(query: Union[int, float], field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.lt(query: Union[int, float], field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.lte(query: Union[int, float], field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.date(query: Union[datetime.date, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is equal to query

CryptographicFields.filters.date_lt(query: Union[datetime.date, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.date_lte(query: Union[datetime.date, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.date_gt(query: Union[datetime.date, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.date_gte(query: Union[datetime.date, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.date_range(query: Tuple[Union[datetime.date, datetime.datetime], Union[datetime.date, datetime.datetime]], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.year(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.year_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.year_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.year_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.year_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.year_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.month(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.month_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.month_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.month_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.month_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.month_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.day(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.day_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.day_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.day_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.day_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.day_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.time(query: Union[datetime.time, datetime.datetime], field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.time_lt(query: Union[datetime.time, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.time_lte(query: Union[datetime.time, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.time_gt(query: Union[datetime.time, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.time_gte(query: Union[datetime.time, datetime.datetime], field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.time_range(query: Tuple[Union[datetime.time, datetime.datetime], Union[datetime.time, datetime.datetime]], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.hour(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.hour_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.hour_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.hour_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.hour_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.hour_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.minute(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.minute_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.minute_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.minute_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.minute_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.minute_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.second(query: int, field_name: str, object: Any) → bool[source]

Checks if value of object is equal to query

CryptographicFields.filters.second_lt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than value of query

CryptographicFields.filters.second_lte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is less than or equal to value of query

CryptographicFields.filters.second_gt(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than value of query

CryptographicFields.filters.second_gte(query: int, field_name: str, object: Any) → bool[source]

Check if value of object is greater than or equal to value of query

CryptographicFields.filters.second_range(query: Tuple[int, int], field_name: str, object: Any) → bool[source]

Check if value of object is in range of query

CryptographicFields.filters.regex(query: Any, field_name: str, object: Any) → bool[source]

Checks if query pattern is present in value of object

Indices and tables