aboutsummaryrefslogtreecommitdiffstats
path: root/docs/examples/blogpost.rst
blob: 36b9d9825ed5c380a7b6dcec7a74a0bd60b0e6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.. _blogposts:

Blog Posts API
==============

* http://api.django-rest-framework.org/blog-post/

The models
----------

In this example we're working from two related models:

``models.py``

.. include:: ../../examples/blogpost/models.py
    :literal:

Creating the resources
----------------------

Once we have some existing models there's very little we need to do to create the API.
Firstly create a resource for each model that defines which fields we want to expose on the model.
Secondly we map a base view and an instance view for each resource.
The generic views :class:`.ListOrCreateModelView` and :class:`.InstanceModelView` provide default operations for listing, creating and updating our models via the API, and also automatically provide input validation using default ModelForms for each model.

``urls.py``

.. include:: ../../examples/blogpost/urls.py
    :literal: