Skip to main content

Extension for Django Rest Framework to enable simple sideloading

Project description

=============================
drf-sideloading
=============================

.. image:: https://badge.fury.io/py/drf-sideloading.svg
:target: https://badge.fury.io/py/drf-sideloading
:alt: Package Index

.. image:: https://travis-ci.org/namespace-ee/django-rest-framework-sideloading.svg?branch=master
:target: https://travis-ci.org/namespace-ee/django-rest-framework-sideloading
:alt: Build Status

.. image:: https://codecov.io/gh/namespace-ee/django-rest-framework-sideloading/branch/master/graph/badge.svg
:target: https://codecov.io/gh/namespace-ee/django-rest-framework-sideloading
:alt: Code Coverage

.. image:: https://readthedocs.org/projects/drf-sideloading/badge/?version=latest
:target: http://drf-sideloading.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000
:alt: License is MIT
:target: https://github.com/namespace-ee/drf-sideloading/blob/master/LICENSE

Extension for Django Rest Framework to enable simple sideloading

Documentation
-------------

The full documentation is at https://drf-sideloading.readthedocs.io.

Quickstart
----------

Install drf-sideloading::

pip install drf-sideloading

Import Mixin `SideloadableRelationsMixin`:

.. code-block:: python

from drf_sideloading.mixins import SideloadableRelationsMixin


Include mixin in view and define serializers dict ``sideloadable_relations`` as shown in examples

It is ``required`` to define and indicate a ``primary`` relationship in ``sideloadable_relations`` dict

Example of using mixin in ViewSet

.. code-block:: python

class ProductViewSet(SideloadableRelationsMixin, viewsets.ModelViewSet):
"""
A simple ViewSet for viewing and editing products.
"""
queryset = Product.objects.all()
serializer_class = ProductSerializer

sideloadable_relations = {
'products': {'primary': True, 'serializer': ProductSerializer},
'categories': {'serializer': CategorySerializer, 'source': 'category', 'prefetch': 'category'},
'suppliers': {'serializer': SupplierSerializer, 'source': 'supplier', 'prefetch': 'supplier'},
'partners': {'serializer': PartnerSerializer, 'source': 'partners', 'prefetch': 'partners'}
}


Request::

GET /product/?sideload=categories,partners,suppliers

Response::

{
"categories": [
{
"id": 1,
...
}
],
"partners": [
{
"id": 1,
...
},
{
"id": 2,
...
},
{
"id": 3,
...
}
],
"products": [
{
"id": 1,
"name": "Product 1",
"category": 1,
"supplier": 1,
"partner": [
1,
2,
3
]
}
],
"suppliers": [
{
"id": 1,
...
}
]
}




Example Project
-----------------------

directory `example` includes example project
you can setup and run int locally using following commands

::

cd example
sh scripts/devsetup.sh
sh scripts/dev.sh


Contributing
-------------

For detailed description see `CONTRIBUTING Notes <https://github.com/namespace-ee/django-rest-framework-sideloading/blob/master/CONTRIBUTING.rst>`_

Setup for contribution


::

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements_dev.txt


Test with specific env

::

$ tox --listenvs
py27-django18-drf34
py27-django19-drf34
# ...
$ tox -e py27-django19-drf34


Test coverage

::

$ make coverage



Use `pyenv <https://github.com/pyenv/pyenv>`_ for testing using different versions locally

# TODO

* fix documentation
* improve coverage



Credits
-------

Tools used in rendering this package:

* Cookiecutter_
* `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage




History
-------


0.1.10 (2017-07-20)
++++++++++++++++++

* Support for django2.0


0.1.8 (2017-07-20)
++++++++++++++++++

* change sideloadable_relations dict
* always required to define 'serializer'
* key is referenced to url and serialized in as rendered json
* add `source` which specifies original model field name


0.1.0 (2017-07-20)
++++++++++++++++++

* First release on PyPI.

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

drf-sideloading-0.1.10.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

drf_sideloading-0.1.10-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file drf-sideloading-0.1.10.tar.gz.

File metadata

File hashes

Hashes for drf-sideloading-0.1.10.tar.gz
Algorithm Hash digest
SHA256 3428bbfc0011b7dbe823a18af284e53647441d4982ac65d6e922cbb12d8806ce
MD5 a075a9a0c163ec4cc1dbd9fc56157683
BLAKE2b-256 122821654b4fa2dac98b426d4c86b951768c86031442db3f89d87bbab7800523

See more details on using hashes here.

Provenance

File details

Details for the file drf_sideloading-0.1.10-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for drf_sideloading-0.1.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c2866233788682481e4e1a8226d32cc5774a7de95b3ecf3dcfe1214cde19dbc6
MD5 a82c5082b3dee6096a3bf14a341e03ed
BLAKE2b-256 fcf9238bff97dbc98950586711c9c040a5e38a6a4393920187e78329806ba2ba

See more details on using hashes here.

Provenance

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