Last active
February 23, 2018 15:00
-
-
Save andrewtremblay/c30313b1017736812102eac7c31aee32 to your computer and use it in GitHub Desktop.
An example of how to use common model classes.
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
# import CommonModel, CommonSerializer, CommonViewSet | |
# from https://gist.github.com/andrewtremblay/94c485f816f3095d7e86668b97b1a668 | |
class Note(CommonModel): | |
"""Note content, written by a user.""" | |
text_body = models.TextField(default="") | |
class NoteSerializer(CommonSerializer): | |
"""Serialize requests for Text Content.""" | |
# some permission_classes like (IsAuthenticated, ) | |
# some authentication_classes like (SessionAuthentication, OAuth2Authentication,) | |
class Meta: | |
"""Meta class for TextContentSerializer.""" | |
model = TextContent | |
fields = ['id', 'text_body'] + CommonSerializer.common_fields | |
class NoteViewSet(CommonViewSet): | |
"""Shows CRUD endpoints for Notes.""" | |
queryset = Note.objects.all() | |
serializer_class = NoteSerializer | |
# some parser_classes like parsers.JSONParser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment