Instantly share code, notes, and snippets.

Embed
What would you like to do?
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