Skip to main content

A simple Django Field for storing auto-incrementing field.

Project description


Installation

Install django-composite-auto-field:

pip install django-composite-auto-field

Usage

This field uses Django’s Aggregate and Max functions to extract the latest code from the database and does a minimum of parsing to calculate the next code. This avoids having to store a counter in the database. Therefore, for correct operation, once the field arguments have been set, it is advisable not to modify them anymore, or to manually act on the codes already calculated and stored in the database.

Import to your models:

from django_composite_auto_field.fields import CompositeAutoField

Usage:

class Order(models.Model):
    code = CompositeAutoField(prefix='ORD', use_year=True, zeros=5)

Arguments:

prefix      # It's used to indicate prefix for the code
use_year    # When it's True, last two numbers of current year will be used after prefix
zero        # Indicated number of zeros before the number

Run:

python manage.py makemigrations
python manage.py migrate

For example. Using Arguments from above as shown, will result in codes:

ORD2100001
ORD2100002
ORD2100003
...

If the year is used, every year the counter will be automatically reset and the count will restart with 1.

Release Notes

  • 0.1.1 - initial release
    • provides CompositeAutoField for storing auto-incrementing field

    • supports Django 3.1 on python 3.6, 3.7, 3.8 and 3.9 - as per the official django docs

Todo

  • ❌ Create test cases

  • ✔️ Initial release on GitHub

  • ✔️ Initial release on PyPi

  • ❌ Improve last code parsing for make arguments changeable

Contributing

It’s an open source project, so any contributions are welcome!

Project details


Download files

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

Source Distribution

django-composite-auto-field-0.1.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

django_composite_auto_field-0.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django-composite-auto-field-0.1.2.tar.gz.

File metadata

  • Download URL: django-composite-auto-field-0.1.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django-composite-auto-field-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cdd18ed892b8862f34ad498326f2f75124b505dceeb19ea821cb2f656e2dd849
MD5 8ad38a96fe078144029b59138a11265c
BLAKE2b-256 f0549e6e4671f802d935e141a731c1fd2749172d110f26f938639b5e05e69cf5

See more details on using hashes here.

File details

Details for the file django_composite_auto_field-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: django_composite_auto_field-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django_composite_auto_field-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88d4efa58aa79a5a81c3baae39c23bbd03be8062fa5cba6157b5c746ef32a14b
MD5 c04d287ca1ca61873138467db54ca61b
BLAKE2b-256 c2d45eb8f896754f5c9b1047d147a830ebb846ef72122a92e12dbffe81f6993d

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 Pingdom Monitoring Sentry Error logging StatusPage Status page