-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
JSONAPI Resource | ||
================ | ||
|
||
Resources are related to Django models. | ||
Basic customization is done in Resource.Meta class. | ||
Exampele of resource declaration is shown below: | ||
|
||
.. code-block:: python | ||
from jsonapi.api import API | ||
from jsonapi.resource import Resource | ||
from django.conf import settings | ||
api = API() | ||
@api.register | ||
class UserResource(Resource): | ||
class Meta: | ||
model = settings.AUTH_USER_MODEL | ||
authenticators = [Resource.AUTHENTICATORS.SESSION] | ||
fieldnames_exclude = 'password', | ||
@api.register | ||
class AuthorResource(Resource): | ||
class Meta: | ||
model = 'testapp.Author' | ||
allowed_methods = 'GET', 'POST', 'PUT', 'DELETE' | ||
@api.register | ||
class PostWithPictureResource(Resource): | ||
class Meta: | ||
model = 'testapp.PostWithPicture' | ||
fieldnames_include = 'title_uppercased', | ||
page_size = 3 | ||
@staticmethod | ||
def dump_document_title(obj): | ||
return obj.title | ||
Available Meta parameters: | ||
|
||
=================== ================= ===================== ================================= | ||
Name Type Default Usage | ||
=================== ================= ===================== ================================= | ||
model str None. Need to specify '<appname>.<modelname>' | ||
allowed_methods tuple ('GET') tuple of capitalized HTTP methods | ||
authenticators list [] [Resource.AUTHENTICATORS.SESSION] | ||
fieldnames_include list [] list of field names | ||
fieldnames_exclude list [] list of field names | ||
page_size int None integer if need pagination | ||
form django.forms.Form Default ModelForm form to use | ||
=================== ================= ===================== ================================= |