1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #15091 -- Allowed passing custom encoder to JSON serializer.

This commit is contained in:
Berker Peksag
2016-06-28 14:48:19 +03:00
committed by Tim Graham
parent 6bf7964023
commit c1b6f554e4
4 changed files with 37 additions and 2 deletions

View File

@@ -265,6 +265,17 @@ work::
return force_text(obj)
return super(LazyEncoder, self).default(obj)
You can then pass ``cls=LazyEncoder`` to the ``serializers.serialize()``
function::
from django.core.serializers import serialize
serialize('json', SomeModel.objects.all(), cls=LazyEncoder)
.. versionchanged:: 1.11
The ability to use a custom encoder using ``cls=...`` was added.
Also note that GeoDjango provides a :doc:`customized GeoJSON serializer
</ref/contrib/gis/serializers>`.