djangosnippets.org: Latest snippets tagged with 'serializer'https://djangosnippets.org/tags/serializer/2017-11-24T03:29:53.156745-06:00Serializer/Deserializer with utf-8/timezone support
2017-11-24T03:29:53.156745-06:00muciushttps://djangosnippets.org/snippets/10630/<p>Sorry, this snippet only tested on Django ver.2.0rc1.</p>
Freely redistributableutf8-friendly dumpdata management command for yaml (no escape symbols) #2
2016-09-08T09:09:16.423595-05:00muciushttps://djangosnippets.org/snippets/10586/<p>This is a revised version of https://djangosnippets.org/snippets/2921/</p>
Freely redistributableJSON serializer supporting natural primary keys
2014-03-25T09:52:27.175689-05:00bdauvergnehttps://djangosnippets.org/snippets/3038/<p>Copy this file into <code>your_app/serializer.py</code>, and add this to your settings:</p>
<pre><code>SERIALIZATION_MODULES = {
'json': 'your_app.serializer',
}
</code></pre>
<p>Now you can dump your models with the classical <code>dumpdata -n</code> command and load it with <code>loaddata</code> and get support for natural primary keys and not only with foreign keys and many …</p>
Freely redistributableA slightly better YAML serializer
2011-06-10T12:22:21.955708-05:00wapcaplethttps://djangosnippets.org/snippets/2461/<p>I find Django's default YAML serializer output too repetitive, so I came up with this customized version that avoids outputting the model name for every single object, and makes the primary key into an index for the object's fields. This allows many simple model instances to be serialized as one-liners. …</p>
Freely redistributableCSV serializer
2010-10-25T00:25:00.270520-05:00stringifyhttps://djangosnippets.org/snippets/2240/<p>CSV serialization for models. Can be used via the dumpdata/loaddata management commands or programmatically using the django.core.serializers module. Supports multiple header lines and natural keys.</p>
<p>Add the following to settings.py:</p>
<pre><code>SERIALIZATION_MODULES = {
'csv' : 'path.to.csv_serializer',
}
</code></pre>
<p>Examples of usage:</p>
<pre><code>$ python manage.py dumpdata --format csv auth.user > users.csv
from …</code></pre>
Freely redistributableJSON encoding middleware
2008-06-13T11:59:27.872250-05:00kcarnoldhttps://djangosnippets.org/snippets/803/<p>Makes it really easy to return JSON from your views: just return a dict.</p>
<p>(Also from <a href="http://code.google.com/p/django-webapp/">django-webapp</a>.)</p>
Freely redistributableExtended JSON encoder
2008-06-13T11:47:55.864465-05:00kcarnoldhttps://djangosnippets.org/snippets/800/<p>The Django JSON encoder already extends the <code>simplejson</code> encoder a little; this extends it more and gives an example of how to go about further extension.</p>
<p>Hopefully <code>newserializers</code> (see the community aggregator today) will supercede this, but until then, it's useful.</p>
Freely redistributable