Library with several useful Models for Django to help you make your Models smart or with less code
Project description
Para visualizar o README em português.
Django Models is Library with several useful Models for Django to help you make your templates smart or with less code
Requirements
Python 3.x
Django 1.11 or later
Features
Generic Models
ActiveModel
Model with is_active boolean field
CodeModel
Model with a code field that automatically generates a hash of 16 characters by default. Useful to identify your record in a more humane way
SerializerModel
Model to return a dict with all data of your django instance without a serializer.
Example:
Your Model
from django_models.models import SerializerModel
...
class YourModel(SerializerModel)
name = models.CharField(max_length=255)
...
Usage
In[1]: from . import YourModel
In[2]: instance = YourModel.objects.first()
In[3]: user.serialize()
Out[3]: {'id': 1, 'name': 'first record', ...}
SlugModel
Model with a slug field. Useful to use in urls or nominal references
TimestampedModel
Model with the DateTime, created_at and updated_at fields. Useful to control when any changes were made.
UUIDModel
Model that uses the id field as a UUID. Useful to be able to have a unique identifier without worrying about sequences.
History models
History Model Model that track each save to generate a History Changes of a record
Signals Models
With SignalModel it allows you to handle or execute an event according to Django’s Signals.
- On Save:
pre_save (Before Saving)
post_save (After saving)
- On Erase:
pre_delete (Before Erasing)
post_delete (After Deleting)
Example using Pre-save signal
Note: This will be made before you save your model
from django_models.models import SignalsModel
...
class YourModel(SignalsModel)
...
def pre_save(self):
do_something()
Soft Delete Signal Model
SoftDeleteSignalModel Models
It is the SignalsModel with soft delete implemented. Allows nothing you delete to be really deleted from the system and easy to recover
How to install
Getting It
You can get Django Models by using pip:
$ pip install django-models
If you want to install it from source, grab the git repository from GitHub and run setup.py:
$ git clone git@github.com:rhenter/django_models.git
$ cd django_models
$ python setup.py install
Settings
To enable django_models in your project you need to add it to INSTALLED_APPS in your projects settings.py file:
INSTALLED_APPS = (
...
'django_models',
...
)
Documentation
Check out the latest django-models documentation at GitHub Pages
Contributing
Please send pull requests, very much appreciated.
Fork the repository on GitHub.
Make a branch off of master and commit your changes to it.
Install requirements. pip install -r requirements-dev.txt
Install pre-commit. pre-commit install
Run the tests with cd test-django-project; py.test -vv -s
Create a Pull Request with your contribution
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
Built Distribution
File details
Details for the file django-models-0.5.1.tar.gz
.
File metadata
- Download URL: django-models-0.5.1.tar.gz
- Upload date:
- Size: 58.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3884d108d0c64e664ad414648c0b6da218a1e3dbe98451edd5c70e47467252f1 |
|
MD5 | c6f64611ae70cc59aa4981249123186d |
|
BLAKE2b-256 | afd785a86d5318478a7a367fe1ca2cf47352cb31fe03a75c72d7668edb2909c8 |
File details
Details for the file django_models-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: django_models-0.5.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae828d7e54a66b718d878661451115d6be38c8a0df8dd869fd3e8be19ebcf096 |
|
MD5 | a162c0ebf07bd6927b41acd4862da131 |
|
BLAKE2b-256 | a78686589bc3bb371a944ebec62b898d7be364e4ed0a476bafa333d5346675d7 |