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.0 - 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
Hashes for django-composite-auto-field-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52df464e44b268af74d4604b3a03f44e5ba3c68b9c1a6936998cde769448e0cd |
|
MD5 | 8b41af262e5ef191390f31025df1a5c5 |
|
BLAKE2b-256 | 2305d8ff6696a40aa80619a58130a9cf274d953b1d714a5f2d357ba210db4966 |