Skip to content

Instantly share code, notes, and snippets.

@andrewtremblay
Last active February 23, 2018 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewtremblay/c30313b1017736812102eac7c31aee32 to your computer and use it in GitHub Desktop.
Save andrewtremblay/c30313b1017736812102eac7c31aee32 to your computer and use it in GitHub Desktop.
An example of how to use common model classes.
# 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