semvec/pypi-packages huggingface dataset:
django-generic-models 0.3
django-generic-models provides subclassed models with a clear API for fetching superclasses, subclasses and making comparison.
License: MIT
Requires Python: >=3.4, <3.7
Keywords: multi-table inheritance,django,subclass,superclass

=======
django-generic-models
=======

.. image:: https://travis-ci.org/jpmelos/django-generic-models.svg?branch=master
    :target: https://travis-ci.org/jpmelos/django-generic-models

django-generic-models provides subclassed models with a clearer API for fetching superclasses, subclasses and making comparison.

Supports:

* Python 3.4, 3.5 and 3.6.
* Django 1.8, 1.9, 1.10, 1.11 and 2.0.

------------
Installation
------------

::

    $ pip install django-generic-models

-----------
Basic usage
-----------

Declare the superclass as a subclass of ``TypedModel``::

    from genericmodels.models import TypedModel

    class Animal(TypedModel):
        name = CharField(max_length=30)

        def say_something(self):
            raise NotImplementedError


Then, declare the subclasses as usual::

    from django.db.models import CharField

    class Cat(Animal):
        color = CharField(max_length=30)

        def say_something(self):
            return 'meow'

You'll be able to get the specific instance of ``Animal`` or the generic instance of ``Cat`` very easily with::

    cat = Cat()
    animal = cat.generic
    cat = animal.specific

Comparison also works::

    >>> print(cat == animal)
    True

Even though they are not the same object in memory, and one is a ``Cat`` instance and the other is an ``Animal`` instance, they are still the same object, semantically.

For an example of working code, check the ``test_app``.

-----------
Development
-----------

Install for development and with dependencies::

    $ pip install -e .[dev]

Asserting code quality
^^^^^^^^^^^^^^^^^^^^^^

::

    $ python dev.py quality


Running the tests
^^^^^^^^^^^^^^^^^

To run the tests, use::

    $ python dev.py test

To run the tests with ``tox``::

    $ tox

Packaging for PyPI distribution
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    $ python dev.py package

The build will happen if the repository is clean: no untracked files are found. If not, you can see what's wrong with ``git clean -dfx --dry-run`` and remove or track and commit those files.

Builds will be available at ``dist``, in wheel and source.

----------
Contribute
----------

Pull requests are welcome.