Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

Introduction to demo fixtures

A fixture, in real life, is a piece of furniture in a house, such as a kitchen, that is considered an integral part of the house. Django uses the word to designate a collection of data records that can be loaded into the database of a new site.

Fixtures are part of the application code

Every plugin can have a subdirectory named fixtures.

fixtures

A subdirectory of a plugin that contains a number of fixture files in different formats. Django will discover this directory when you run the loaddata command. Read more about it in the Django documentation.

In Lino we usually don't write fixtures in XML or JSON but in Python. That's why our fixtures directories also contain a __init__.py file.

Demo fixtures

Lino extends Django's fixtures by defining the concept of demo fixtures.

The demo fixtures of an application are a list of fixtures to be loaded by pm prep. This list is simply defined by the lino.core.site.Site.demo_fixtures site attribute.

For example, the chatter application has the following value for this attribute:

>>> from lino import startup
>>> startup('lino_book.projects.chatter.settings')
>>> from django.conf import settings
>>> settings.SITE.demo_fixtures
['std', 'demo', 'demo2']

This means that saying pm prep on a site that runs chatter is equivalent to saying pm initdb std demo demo2

The advantage is that you don't need to know the list of demo fixtures when invoking the command. The default list of demo fixtures to load for initializing a "clean" demo database can be long and difficult to remember, and (more importantly) it can change when an application evolves. As a system administrator you usually don't want to know such details. They are to be specified by the application developer in the demo_fixtures attribute. As a future application developer you can learn more about them in Writing Python fixtures.