Fixtures are the best way to provide initial data to a your site, or save data after populate your database.
Note
See fixtures in Django for more information.
Django by default load all initial_data.* fixtures files placed in every application fixtures it found.
Also, Merengue has a way to define explicit fixtures file to load, using the SITE_FIXTURES setting, as this example:
SITE_FIXTURES = {
'section': ('initial_content.xml', ),
'fooapp': ('fooapp_content.xml', ),
}
The format of this dict is 'application_name': ('fixture1.format', 'fixture2.format').
Data loading into your new site is done everytime you execute python manage.py migrate command. The migrate command (implemented in South application) will migrate every installed application and Merengue will load every fixtures you define for that application. Those fixtures will be found in your FIXTURES_DIRS setting (by default in a fixtures directory inside your Merengue project).
Merengue load initial data in your site using Django serialization framework. By default Merengue uses the XML format to load data, overriding default Django XML serializer, adding these improvements:
You can understand the first improvement looking at this fixture fragment:
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="1" model="base.basecontent">
<field type="SlugField" name="slug">welcome</field>
<field type="CharField" name="name_es">Bienvenido a Merengue</field>
<field type="CharField" name="name_en">Welcome to Merengue</field>
<field type="TextField" name="description_en">
Merengue is a full-featured CMS useful for creating websites without writing a single line of code or customizing and extending with any of the plethora of existing Django applications.
</field>
<field type="TextField" name="description_es">
Merengue is a full-featured CMS useful for creating websites without writing a single line of code or customizing and extending with any of the plethora of existing Django applications.
</field>
...
</object>
</django-objects>
As you see, the content have name and description data both for Spanish and English languages. But, what happens if you have configured your site in English and French? Django default XML serializer will fail. Merengue by default has translated data in the fixtures and is more robust to be independent of your site languages.
The second improvement is caused for this use case:
The Merengue XML serializer will omit translatable fields data in languages not configured in your site.
If you want to allow manager edit in a data from fixtures, you can do it adding a overwrite="no" in every <object> XML element, like this:
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="1" model="base.basecontent" overwrite="no">
<field type="SlugField" name="slug">welcome</field>
...
</object>
</django-objects>
With this mark, Merengue will not touch this object when loading fixtures if the object already exists.
Apr 12, 2011