Skip to main content

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

Project description

PyPI latest PyPI Version PyPI License CicleCI Status Coverage Docs

Django Models is Library with several useful templates 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 32 characters hash code to use to identify your record

  • SerializerModel

    Model to return a dict with all data of your django instance without a serializaer.

Example:

Your Model

from django_models.models import SignalsModel
...

class YourModel(SignalsModel)
    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 slug field

  • TimestampedModel

    Model with created_at and updated_at DateTime fields

  • UUIDModel

    Model using the field id as UUID

  • Signals

With SignalModel it allows you to handle or execute an event according to Django’s Signals.

On save:
  • pre_save

  • post_save

On Delete
  • pre_delete

  • post_delete

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()
  • History models

    Model that track each save to generate a History Changes of a record

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 Gitlab and run setup.py:

$ git clone git@github.com:rhenter/django_models.git
$ cd django_models
$ python setup.py install

Installing It

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 Read the Docs

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-0.1.0.tar.gz (18.3 kB view hashes)

Uploaded Source

Built Distribution

django_models-0.1.0-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page