I've got the following serializer:
from rest_framework import serializers
from .models import Product
class ProductSerializer(serializers.ModelSerializer):
""" Serializer for Product object """
class Meta:
model = Product
fields = ['name', 'slug', 'description', 'image', 'price', 'active',]
and the following test:
from django.test import TestCase
from django.urls import reverse
from rest_framework.test import APIClient
from rest_framework import status
from .factories import ProductFactory
from .models import Product
from .serializer import ProductSerializer
PRODUCTS_URL = reverse('product-list')
def create_product(**params):
""" Helper function to create a new product """
return Product.objects.create(**params)
class PublicProductApiTests(TestCase):
"""
Test the public products' API
"""
def setUp(self):
self.client = APIClient()
def test_only_active_products_are_returned(self):
ProductFactory.create_batch(2)
products = Product.objects.all()
serializer = ProductSerializer(products, many=True)
print(serializer.data)
When I print serializer.data
on the screen, I'm getting:
[OrderedDict([('name', 'Shane Fields'), ('slug', 'shane-fields'), ('description', 'Chance yourself conference.'), ('image', '/media/position/school.tiff'), ('price', '2.66'), ('active', False)]), OrderedDict([('name', 'Michael Hall'), ('slug', 'michael-hall'), ('description', 'Office city material room character number cause way.'), ('image', '/media/American/know.txt'), ('price', '-90244357.41'), ('active', True)])]
after passing the queryset to the serializer and printing its data, isn't supposed to print in JSON format? what am I missing?