def post(self, request): serializer = ImportSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) data = serializer.validated_data if 'errors' in data: return Response(data={'errors': data['errors']}, status=BAD_REQUEST) return Response()
def setUpTestData(cls): serializer = ImportSerializer(data=import_data) serializer.is_valid() serializer.save()
def setUpTestData(cls): cls.url = reverse('citizen', kwargs={'import_id': 1, 'citizen_id': 1}) serializer = ImportSerializer(data=import_data) serializer.is_valid() serializer.save()
def import_from_url(request): ser = ImportSerializer(data=request.data, context=dict(user=request.user)) if ser.is_valid(raise_exception=True): ser.save() return Response(ser.validated_data, status=status.HTTP_201_CREATED)
def citizen_list(request, import_id): import_instance = get_object_or_404(Import, id=import_id) serializer = ImportSerializer(import_instance) return Response({'data': serializer.data.get('citizens')})
def import_list(request): serializer = ImportSerializer(data=request.data) serializer.is_valid(raise_exception=True) import_instance = serializer.save() return Response({'data': {'import_id': import_instance.id}}, status=status.HTTP_201_CREATED)