django-related-models

A library designed such that, when provided with a model instance it will return a QuerySet for the rows that are associated with that model instance.


License
BSD-1-Clause
Install
pip install django-related-models==0.1.1

Documentation

Overview

A library designed such that, when provided with a model instance it will return a QuerySet for the rows that are associated with that model instance. It also works well with GenericForeignKey objects.

>>> eminem = Artist.objects.filter(stage_name='Eminem').first()
>>> list(get_related_objects(eminem))
[<Albums: Kamikaze>, <Awards: Grammy>, <Cars: Audi R8 Spyder>]

>>> get_related_objects_mapping(eminem)
{<django.db.models.fields.related.ForeignKey: artist>: set([<Albums: Kamikaze>]),
<django.db.models.fields.related.ForeignKey: artist>: set([<Awards: grammy>]),
<django.contrib.contenttypes.fields.GenericForeignKey object at 0x106ff1f50>: set([<Cars: Audi R8 Spyder>])}

Installation

pip install django-related-models

Documentation

https://django-related-models.readthedocs.io/

Development

The tests are run via tox, which you would need to install (if you don't already have it).

  • To get tox just:

    pip install tox
    
  • To run the all tests run:

    tox