I'm serializing a bunch of objects with:
json = serializers.serialize("json", objects, fields=('name', 'country'))
I have not included 'pk' in my fields list, but the produced JSON includes a primary key with each serialized object. I do not want my API to expose primary keys to the general public.
Short of munging the output JSON, what is the correct way to tell serializers.serialze()
to not include the primary key?
I ended up working around this by 'manually' achieving what I wanted using the underlying simplejson
serializer:
from django.utils import simplejson json = simplejson.dumps( [{'name': o.name, 'country': o.country} for o in objects] )
A little more typing, but works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With