Skip to main content

Travis status:

https://travis-ci.org/WoLpH/django-utils.png?branch=master

Coverage:

https://coveralls.io/repos/WoLpH/django-utils/badge.png?branch=master

Django Utils is a collection of small Django helper functions, utilities and classes which make common patterns shorter and easier. It is by no means a complete collection but it has served me quite a bit in the past and I will keep extending it.

Examples are:

  • Enum based choicefields

  • Models with automatic __str__, __unicode__ and __repr__ functions based on names and/or slugs using simple mixins.

  • Models with automatic updated_at and created_at fields

  • Models with automatic slugs based on the name property.

  • Iterating through querysets in predefined chunks to prevent out of memory errors

The library depends on the Python Utils library.

Documentation is available at: http://django-utils-2.readthedocs.io/en/latest/

Install

To install:

  1. Run pip install django-utils2 or execute python setup.py install in the source directory

  2. Add django_utils to your INSTALLED_APPS

If you want to run the tests, run py.test (requirements in tests/requirements.txt)

Usage

To enable easy to use choices which are more convenient than the Django 3.0 choices system you can use this:

from django_utils import choices


# For manually specifying the value (automatically detects `str`, `int` and `float`):
class Human(models.Model):
    class Gender(choices.Choices):
        MALE = 'm'
        FEMALE = 'f'
        OTHER = 'o'

    gender = models.CharField(max_length=1, choices=Gender)


# To define the values as `male` implicitly:
class Human(models.Model):
    class Gender(choices.Choices):
        MALE = choices.Choice()
        FEMALE = choices.Choice()
        OTHER = choices.Choice()

    gender = models.CharField(max_length=1, choices=Gender)


# Or explicitly define them
class Human(models.Model):
    class Gender(choices.Choices):
        MALE = choices.Choice('m', 'male')
        FEMALE = choices.Choice('f', 'female')
        OTHER = choices.Choice('o', 'other')

    gender = models.CharField(max_length=1, choices=Gender)

A PostgreSQL ENUM field will be coming soon to automatically facilitate the creation of the enum if needed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-utils2-2.9.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_utils2-2.9.0-py2.py3-none-any.whl (17.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-utils2-2.9.0.tar.gz.

File metadata

  • Download URL: django-utils2-2.9.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for django-utils2-2.9.0.tar.gz
Algorithm Hash digest
SHA256 77a77c92968f721a83a49acef793ac102aa44b6fba7af699d6a80314e5c79688
MD5 7d44c4856224f83deac75d671654c052
BLAKE2b-256 05fc145cb9e0691ff32d413a2c775afeb61267ec46995ff8ba4c985203028fe6

See more details on using hashes here.

File details

Details for the file django_utils2-2.9.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_utils2-2.9.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 31ddad599720cc19648b9db382647f221e49bd97a65272a41547ab2438db1243
MD5 043796d1a4db50f7f76a15fc69439998
BLAKE2b-256 1a492419a3e64e4f8c1b77b6770d6f0059050b7cfcd24be728e8df368a008275

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page