Skip to main content

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.

PyPI latest PyPI Version PyPI License GitHub Actions Status Coverage Docs Open Source? Yes!

Django Models is a Library with several useful Models for Django to help you make your templates smart or with less code

Requirements

  • Python 3.8 or later

  • 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

  • HistoryModel Model that tracks each save to generate a Change History of a record

Signals Models

With SignalsModel 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 Delete:
  • pre_delete (Before Deleting)

  • 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. Ensures that nothing you delete is 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.

  1. Fork the repository on GitHub.

  2. Make a branch off of master and commit your changes to it.

  3. Install requirements. pip install -r requirements-dev.txt

  4. Install pre-commit. pre-commit install

  5. Run the tests with cd test-django-project; py.test -vv -s

  6. 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

django_models-1.0.tar.gz (88.6 kB view details)

Uploaded Source

Built Distribution

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

django_models-1.0-py3-none-any.whl (52.7 kB view details)

Uploaded Python 3

File details

Details for the file django_models-1.0.tar.gz.

File metadata

  • Download URL: django_models-1.0.tar.gz
  • Upload date:
  • Size: 88.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for django_models-1.0.tar.gz
Algorithm Hash digest
SHA256 8a1b9ffc9f1112e3bba754c4b5ff46b616cbe5fcd5468d2b80e0985795dc441e
MD5 2dc510676d56351c9ef657a66d280ebc
BLAKE2b-256 f2ae57a9839f185d7cfcc555cc3f2c20731f08918d4b52d4cbdc508f3dd5254c

See more details on using hashes here.

File details

Details for the file django_models-1.0-py3-none-any.whl.

File metadata

  • Download URL: django_models-1.0-py3-none-any.whl
  • Upload date:
  • Size: 52.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for django_models-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 014b2174efed64bb322724402cdab83c568a644d96505a6a00a399bc82d4d549
MD5 c44afb86ed33e40613f09b8a5a7292c7
BLAKE2b-256 e8ad346971b25a6e1edb9f02a2cc3d5554bdd32f356c0263c7a02f1c74153423

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