[Answer]-Tastypie : How to publish a dictionary using Rest API

1👍

You have an example here http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html

You need a subclass of a Resource and to override one or more of the ob_* methods

0👍

Suppose we have a SomeModel model class and it has get_dict_field() function that returns dictionary.

from tastypie.resources import ModelResource
from tastypie import fields
from .models import SomeModel

class CustomResource(ModelResource):
    dict_field = fields.DictField(
        attribute='get_dict_field',
        readonly=True
    )

    class Meta:
        queryset = SomeModel.objects.all()
        resource_name = 'someresname'

        # ....

Leave a comment