Customizable serialization now passing Django's test suite.

42 views
Skip to first unread message

Tom Christie

unread,
May 21, 2012, 7:39:47 AM5/21/12
to django-d...@googlegroups.com
I've been working away on django-serializers lately, and I've now got a
customizable serialization API that's backwards compatible with the existing
serializers, and is passing Django's serializer tests.

Exactly where I take this will depend on how Piotr Grabowski's GSoC project
progresses, but I'd certainly appreciate any input regarding the API design,
or if there would be any obvious blockers that'd prevent something along these
lines making it's way in as a replacement to the existing serializers.

This work intentionally doesn't (yet) address customizable deserialization,
and as such it currently only supports the existing loaddata deserialization.


Running the existing tests with django-serializers
==================================================

* Clone Django

* Install django-serializers

* Replace the existing dumpdata serializers with django-serializer's versions

In `django/core/serializers/__init__.py`, replace these strings:

"django.core.serializers.xml_serializer",
"django.core.serializers.python",
"django.core.serializers.json",
"django.core.serializers.pyyaml"

With these:

"serializers.dumpdata_xml",
"serializers.dumpdata_python",
"serializers.dumpdata_json",
"serializers.dumpdata_yaml"

* Run the serializer tests from Django's 'tests' directory

./runtests.py --settings=test_sqlite serializers serializers_regress


Example use-case
================

I've written a small app `django-auto-api` that uses `django-serializers`
to generate a read-only hyperlinked API for all installed models with `html`,
`json`, `yaml`, `xml` and `csv` outputs.

It demonstrates using custom relational fields between models to use
hyperlinking relationships rather than primary key relationships, and shows
how the customizable serialization can be used to build Web APIs with
very little code.


Summary
=======

As mentioned I'd appreciate any thoughts on what else it might take to bridge
the gap of getting this to the point where it could be adopted into core.

I think it should also serve as a decent point of reference for Piotr's GSoC project, in
particular `django-auto-api` is a good concrete use-case that I'd like any
customizable serialization proposal to be able to handle.


 - Tom

Reply all
Reply to author
Forward
0 new messages