{"id":13367649,"url":"https://github.com/eabglobal/django-rest-framework-collection-json","last_synced_at":"2025-03-12T20:30:48.101Z","repository":{"id":19603362,"uuid":"22854273","full_name":"eabglobal/django-rest-framework-collection-json","owner":"eabglobal","description":null,"archived":true,"fork":false,"pushed_at":"2014-08-20T04:13:37.000Z","size":216,"stargazers_count":10,"open_issues_count":4,"forks_count":6,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-07-30T01:10:48.123Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eabglobal.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-11T20:46:13.000Z","updated_at":"2024-07-30T01:10:48.124Z","dependencies_parsed_at":"2022-08-24T13:40:49.547Z","dependency_job_id":null,"html_url":"https://github.com/eabglobal/django-rest-framework-collection-json","commit_stats":null,"previous_names":["advisory/django-rest-framework-collection-json"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eabglobal%2Fdjango-rest-framework-collection-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eabglobal%2Fdjango-rest-framework-collection-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eabglobal%2Fdjango-rest-framework-collection-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eabglobal%2Fdjango-rest-framework-collection-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eabglobal","download_url":"https://codeload.github.com/eabglobal/django-rest-framework-collection-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243290616,"owners_count":20267749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T00:01:57.396Z","updated_at":"2025-03-12T20:30:47.851Z","avatar_url":"https://github.com/eabglobal.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"=======================================\nDjango Rest Framework - Collection+JSON\n=======================================\n\n.. image:: https://travis-ci.org/advisory/django-rest-framework-collection-json.svg?branch=master\n    :target: https://travis-ci.org/advisory/django-rest-framework-collection-json\n\nThis library adds support for the Collection+JSON hypermedia format to Django Rest Framework. For more information on Collection+JSON see the `official Collection+JSON documentation \u003chttp://amundsen.com/media-types/collection/\u003e`_.\n\nInstallation\n============\n\nInstall django-rest-framework-collection-json with pip::\n\n    pip install django-rest-framework-collection-json\n\n\nUsage\n=====\n\nTo enable the Collection+JSON renderer, either add it as a default renderer in your django settings file::\n\n    'DEFAULT_RENDERER_CLASSES': (\n        'rest_framework_cj.renderers.CollectionJsonRenderer',\n    )\n\n\nor explicitly set the renderer on your view::\n\n    class MyViewSet(ReadOnlyModelViewSet):\n        renderer_classes = (CollectionJsonRenderer, )\n\nRenderer Behavior\n=================\n\nThe Collection+JSON renderer will do it's best to support the built in Django Rest Framework Serializers and Views. However, the renderer is designed to work with Django Rest Framework's hyperlinked views/serializers.\n\nGiven a simple model and an associated view/serializer::\n\n    class Dummy(Model):\n        name = CharField(max_length='100')\n\n    class DummyHyperlinkedModelSerializer(HyperlinkedModelSerializer):\n        class Meta(object):\n            model = Dummy\n            fields = ('url', 'name', )\n\n    class DummyReadOnlyModelViewSet(ReadOnlyModelViewSet):\n        renderer_classes = (CollectionJsonRenderer, )\n        queryset = Dummy.objects.all()\n        serializer_class = DummyHyperlinkedModelSerializer\n\nIf you register the view as follows::\n\n    router = DefaultRouter()\n    router.register('dummy', DummyReadOnlyModelViewSet)\n    urlpatterns = patterns(\n        '',\n        (r'^rest-api/', include(router.urls)),\n    )\n\nNavigating to the url /rest-api/dummy/ will generate a collection+JSON containing serialized dummy objects in it's items array.::\n\n    \"items\": [\n        {\n            \"href\": \"http://foobar.com/rest-api/dummy/1\"/,\n            \"data\": [\n                {\n                    \"name\": \"name\",\n                    \"value\": \"foo\"\n                },\n            ]\n        },\n        {\n            \"href\": \"http://foobar.com/rest-api/dummy/2/\",\n            \"data\": [\n                {\n                    \"name\": \"name\",\n                    \"value\": \"bar\"\n                },\n            ]\n        }\n    ]\n\nForeign key/Many to Many relationships will be rendered in an item's links array::\n\n    children = ManyToManyField('Child')\n\n    \"links\": [\n        {\n            \"href\": \"http://foobar.com/rest-api/child/1/\",\n            \"rel\": \"children\"\n        },\n        {\n            \"href\": \"http://foobar.com/rest-api/child/2/\",\n            \"rel\": \"children\"\n        },\n    ]\n\nThe renderer will also recognize the default router and provide links its resources::\n\n    {\n        \"collection\": {\n            \"href\": \"http://foobar.com/rest-api/\",\n            \"items\": [],\n            \"version\": \"1.0\",\n            \"links\": [\n                {\n                    \"href\": \"http://foobar.com/rest-api/dummy/\",\n                    \"rel\": \"dummy\"\n                },\n            ]\n        }\n    }\n\nLink Fields\n===========\n\nDjango Rest Framework Colleciton+JSON also includes a new LinkField class for linking to arbitrary resources.::\n\n    class DummyHyperlinkedModelSerializer(HyperlinkedModelSerializer):\n        related_link = LinkField('get_related_link')\n\n        class Meta(object):\n            model = Dummy\n            fields = ('url', 'name', 'related_link')\n\n        def get_related_link(self, obj):\n            return 'http://something-relavent.com/'\n\n    \"items\": [\n        {\n            \"href\": \"http://foobar.com/rest-api/dummy/1\"/,\n            \"data\": [\n                {\n                    \"name\": \"name\",\n                    \"value\": \"foo\"\n                },\n            ],\n            \"links\": [\n                {\n                    \"rel\": 'related_link',\n                    \"href\": 'http://something-relavent.com',\n                }\n            ]\n        },\n    ]\n\nUnit Testing\n============\n\nYou can run the unit tests against your current environment by running::\n\n    $ python setup.py test\n\nYou can also use tox::\n\n    $ tox\n\nThe build environments in the tox configuration are designed to match the builds supported by Django Rest Framework.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feabglobal%2Fdjango-rest-framework-collection-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feabglobal%2Fdjango-rest-framework-collection-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feabglobal%2Fdjango-rest-framework-collection-json/lists"}