diff --git a/companies/serializers.py b/companies/serializers.py index 5e700fb..231aea9 100644 --- a/companies/serializers.py +++ b/companies/serializers.py @@ -8,7 +8,7 @@ from utils.tag_serializers import TagListSerializerField, TaggitSerializer class CompanySerializer(TaggitSerializer, serializers.ModelSerializer): tags = TagListSerializerField(required=False) - geo = PointField(required=False) + geo = PointField(required=False, allow_null=True) class Meta: model = Company diff --git a/companies/views.py b/companies/views.py index 94556e4..a7cd54d 100644 --- a/companies/views.py +++ b/companies/views.py @@ -1,7 +1,6 @@ import logging from django.shortcuts import render -from django.core import serializers from django.core.mail import EmailMessage from django.template.loader import render_to_string diff --git a/core/serializers.py b/core/serializers.py index 69e4f90..e71c71f 100644 --- a/core/serializers.py +++ b/core/serializers.py @@ -1,19 +1,21 @@ from rest_framework import serializers - +from django.contrib.auth import get_user_model from . import models +User = get_user_model() + class CustomUserSerializer(serializers.ModelSerializer): class Meta: - model = models.CustomUser + model = User fields = ('email', 'full_name', 'role', 'is_active') class CustomUserReadSerializer(serializers.ModelSerializer): class Meta: - model = models.CustomUser + model = User fields = ('id', 'email', 'full_name', 'role', 'is_active', 'provider', 'notify') diff --git a/core/views.py b/core/views.py index c496f57..0d0a8d2 100644 --- a/core/views.py +++ b/core/views.py @@ -7,7 +7,6 @@ import datetime from django.shortcuts import render from django.http import HttpResponse from django.contrib.auth import get_user_model -from django.core import serializers from django.utils.http import urlsafe_base64_decode from django.utils.encoding import force_text @@ -108,8 +107,9 @@ class UpdateUserView(UpdateAPIView): @permission_classes([IsAuthenticated,]) def my_user(request): qs = User.objects.filter(email=request.user.email) - data = serializers.serialize('json', qs) - return Response(data=data) + user_serializer = core_serializers.CustomUserReadSerializer(qs, many=True) + return Response(data=user_serializer.data) + @api_view(['POST',]) @permission_classes([IsAdminUser,]) diff --git a/history/views.py b/history/views.py index e6a0b92..e615f9e 100644 --- a/history/views.py +++ b/history/views.py @@ -1,5 +1,4 @@ from django.shortcuts import render -from django.core import serializers # Create your views here. from rest_framework import viewsets diff --git a/products/tests.py b/products/tests.py index da3945a..0b39a8c 100644 --- a/products/tests.py +++ b/products/tests.py @@ -390,12 +390,11 @@ class ProductSearchTest(TestCase): url = f"{self.endpoint}?query_string={query_string}" # send in request response = self.client.get(url) - + # import ipdb; ipdb.set_trace() # check re sponse self.assertEqual(response.status_code, 200) # check for object creation - data = json.loads(response.data) - self.assertEquals(len(data), len(expected_instances)) + self.assertEquals(len(response.data), len(expected_instances)) class MyProductsViewTest(APITestCase): diff --git a/products/views.py b/products/views.py index dc85de3..d6522af 100644 --- a/products/views.py +++ b/products/views.py @@ -6,7 +6,6 @@ from functools import reduce from django.shortcuts import render from django.conf import settings -from django.core import serializers from django.db.models import Q # Create your views here. @@ -46,8 +45,8 @@ class ProductViewSet(viewsets.ModelViewSet): @permission_classes([IsAuthenticated,]) def my_products(request): qs = Product.objects.filter(creator=request.user) - data = serializers.serialize('json', qs) - return Response(data=data) + product_serializer = ProductSerializer(qs) + return Response(data=product_serializer.data) @api_view(['POST',]) @@ -167,7 +166,7 @@ def product_search(request): result_set.add(item) # serialize and respond - data = serializers.serialize('json', result_set) - return Response(data=data) + product_serializer = ProductSerializer(result_set) + return Response(data=product_serializer.data) except Exception as e: return Response({"errors": {"details": str(type(e))}}) diff --git a/stats/views.py b/stats/views.py index 6b51bac..a8f7532 100644 --- a/stats/views.py +++ b/stats/views.py @@ -1,5 +1,4 @@ from django.shortcuts import render -from django.core import serializers # Create your views here. from rest_framework import viewsets