Skip to content
This repository has been archived by the owner on Oct 21, 2018. It is now read-only.

Commit

Permalink
the way to do bulk create in DRF 3.0 ... bleh
Browse files Browse the repository at this point in the history
but hey, the tests pass!
  • Loading branch information
qdonnellan committed Jan 13, 2015
1 parent 1b382ad commit 7862c4d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion api/admissions/views.py
Expand Up @@ -74,12 +74,22 @@ class ApplicationTemplateViewSet(viewsets.ModelViewSet):
serializer_class = StudentApplicationTemplateSerializer
filter_fields = ('is_default',)

class ApplicantAdditionalInformationViewSet(viewsets.ModelViewSet, BulkCreateModelMixin):
class ApplicantAdditionalInformationViewSet(viewsets.ModelViewSet):

permission_classes = (ApplicantPermissions,)
queryset = ApplicantAdditionalInformation.objects.all()
serializer_class = ApplicantAdditionalInformationSerializer

def get_serializer(self, *args, **kwargs):
""" overriding the default behavior to support bulk create,
for reference: stackoverflow.com/questions/27869841/how-to-post-put-json-data-to-listserializer/27871396#27871396
"""
if "data" in kwargs:
data = kwargs["data"]
if isinstance(data, list):
kwargs["many"] = True
return super(ApplicantAdditionalInformationViewSet, self).get_serializer(*args, **kwargs)

class ApplicantForeignKeyRelatedFieldChoicesViewSet(viewsets.ViewSet):

def list(self, request):
Expand Down

0 comments on commit 7862c4d

Please sign in to comment.