Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

The Python serializer

The lino.utils.dpy module defines Lino’s Python serializer and deserializer, which is used for writing and loading demo data, making backups and migrating databases.

Concept and implementation is one of the important concepts which Lino adds to a Django project. It is fully the author’s work, and we didn’t yet find a similar approach in any other framework [1]. In March 2009 Luc suggested to merge it into Django or make it available outside of Lino as well (Django ticket #10664), but that idea is sleeping since then.

A serializer is run by the dumpdata command and writes data into a file which can be used as a fixture. A deserializer is run by loaddata and loads fixtures into the database.

Basic idea:

When a Lino application starts up, it sets your SERIALIZATION_MODULES setting to {“py” : “lino.utils.dpy”}. This tells Django to associate the .py ending to the lino.utils.dpy.Deserializer class when loading (“deserializing”) fixtures.

This deserializer` expects every Python fixture to define a global function objects which it expects to return (or yield) the list of model instances to be added to the database.