skip to navigation
skip to content

django-generic-models 0.2

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

=======
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.3, 3.4, 3.5 |
+--------+----------------+
| Django | 1.8, 1.9, 1.10 |
+--------+----------------+

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

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

::

$ python dev.py quality

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.


 
File Type Py Version Uploaded on Size
django-generic-models-0.2.tar.gz (md5) Source 2017-03-26 4KB
django_generic_models-0.2-py3-none-any.whl (md5) Python Wheel py3 2017-03-26 7KB