Hey DRF Group,
I have a question I couldn't find the documentation about, so if someone
might hint me into the right direction I'd be thankful.
So, I'd like to refactor, if possible, the DocumentTemplateView below into
the DocumentTemplateModelViewSet - there are DocumentTemplates related to
Projects.
So, as you can see in the corresponding url, there are two object id's in
the url - ah ModelViewSet @action would also need to handle those two.
Things in advance,
Marius
class DocumentTemplateModelViewSet(ModelViewSet):
queryset = DocumentTemplate.objects.all()
serializer_class = DocumentTemplateSerializer
permission_classes = (HasStaffAccess,)
class DocumentTemplateView(views.APIView):
permissions = (HasStaffAccess,)
def get(self, request, project_pk=None, template_pk=None, **kwargs):
project = Project.objects.get(id=project_pk)
template = DocumentTemplate.objects.get(id=template_pk)
rendered = template.render(project)
return Response(rendered)
urlpatterns = [
url(
r"^document-template/project-(?P<project_pk>\d+)/template-(?P<template_pk>\d+)?$",
DocumentTemplateView.as_view(),
name="api.document.template",
)
]
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.