mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
31 lines
803 B
ReStructuredText
31 lines
803 B
ReStructuredText
ModelResource example - Blog posts
|
|
==================================
|
|
|
|
* http://api.django-rest-framework.org/blog-post/
|
|
|
|
The models
|
|
----------
|
|
|
|
``models.py``
|
|
|
|
.. include:: ../../examples/blogpost/models.py
|
|
:literal:
|
|
|
|
URL configuration
|
|
-----------------
|
|
|
|
``urls.py``
|
|
|
|
.. include:: ../../examples/blogpost/urls.py
|
|
:literal:
|
|
|
|
Creating the resources
|
|
----------------------
|
|
|
|
Once we have some existing models there's very little we need to do to create the corresponding resources. We simply create a base resource and an instance resource for each model we're working with.
|
|
django-rest-framework will provide the default operations on the resources all the usual input validation that Django's models can give us for free.
|
|
|
|
``views.py``
|
|
|
|
.. include:: ../../examples/blogpost/views.py
|
|
:literal: |