Metadata-Version: 1.1
Name: django-parler-rest
Version: 2.0
Summary: Multilingual support for django-rest-framework
Home-page: https://github.com/edoburu/django-parler-rest
Author: Diederik van der Boor
Author-email: opensource@edoburu.nl
License: Apache 2.0
Download-URL: https://github.com/edoburu/django-parler-rest/zipball/master
Description: django-parler-rest
        ==================
        
        .. image:: https://travis-ci.org/django-parler/django-parler-rest.svg?branch=master
            :target: http://travis-ci.org/django-parler/django-parler-rest
        .. image:: https://img.shields.io/pypi/v/django-parler-rest.svg
            :target: https://pypi.python.org/pypi/django-parler-rest/
        .. image:: https://img.shields.io/pypi/l/django-parler-rest.svg
            :target: https://pypi.python.org/pypi/django-parler-rest/
        .. image:: https://img.shields.io/codecov/c/github/django-parler/django-parler-rest/master.svg
            :target: https://codecov.io/github/django-parler/django-parler-rest?branch=master
        
        Adding translation support to django-rest-framework_.
        
        This package adds support for TranslatableModels from django-parler_ to django-rest-framework_.
        
        
        Installation
        ============
        
        ::
        
            pip install django-parler-rest
        
        Usage
        =====
        
        * First make sure you have django-parler_ installed and configured.
        * Use the serializers as demonstrated below to expose the translations.
        
        First configure a model, following the `django-parler documentation <https://django-parler.readthedocs.io/en/latest/>`_:
        
        .. code-block:: python
        
            from django.db import models
            from parler.models import TranslatableModel, TranslatedFields
        
        
            class Country(TranslatableModel):
                """
                Country database model.
                """
        
                country_code = models.CharField(_("Country code"), unique=True, db_index=True)
        
                translations = TranslatedFields(
                    name = models.CharField(_("Name"), max_length=200)
                    url = models.URLField(_("Webpage"), max_length=200, blank=True)
                )
        
                class Meta:
                    verbose_name = _("Country")
                    verbose_name_plural = _("Countries")
        
                def __unicode__(self):
                    return self.name
        
        
        The model translations can be exposed as a separate serializer:
        
        .. code-block:: python
        
            from rest_framework import serializers
            from parler_rest.serializers import TranslatableModelSerializer, TranslatedFieldsField
            from .models import Country   # Example model
        
        
            class CountrySerializer(TranslatableModelSerializer):
                translations = TranslatedFieldsField(shared_model=Country)
        
                class Meta:
                    model = Country
                    fields = ('id', 'country_code', 'translations')
        
        
        .. note:: The ``TranslatedFieldsField`` can only be used in a serializer that inherits from ``TranslatableModelSerializer``.
        
        
        This will expose the fields as a separate dictionary in the JSON output:
        
        .. code-block:: application/json
        
            {
                "id": 528,
                "country_code": "NL",
                "translations": {
                    "nl": {
                        "name": "Nederland",
                        "url": "http://nl.wikipedia.org/wiki/Nederland"
                    },
                    "en": {
                        "name": "Netherlands",
                        "url": "http://en.wikipedia.org/wiki/Netherlands"
                    },
                    "de" {
                        "name": "Niederlande",
                        "url": "http://de.wikipedia.org/wiki/Niederlande"
                    }
                }
            }
        
        
        Contributing
        ============
        
        This module is designed to be generic. In case there is anything you didn't like about it,
        or think it's not flexible enough, please let us know. We'd love to improve it!
        
        If you have any other valuable contribution, suggestion or idea,
        please let us know as well because we will look into it.
        Pull requests are welcome too. :-)
        
        Running tests
        -------------
        
        Tests are run with `py.test`::
        
            python setup.py test  # install dependencies and run tests with coverage
        
        
        .. _django-parler: https://github.com/django-parler/django-parler
        .. _django-rest-framework: http://www.django-rest-framework.org/
        
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires: Django (>=1.11)
