Development Setup
This guide explains how to set up your local environment for writing migration scripts.
Prerequisite: The Submodule
This repository uses the official Specify 7 repository as a git submodule. Ensure it is initialized:
git submodule update --init --recursive
Python Environment
- Install Requirements:
pip install -r requirements.txt -
Configuration: The migration scripts need to connect to a database (either local or tunneled).
- Copy
config/local_specify_settings.py(it is git-ignored). - Edit it with your database credentials.
- Copy
The Bootstrap Mechanism
To use the Specify 7 Django ORM in standalone scripts, we use a bootstrap.py helper.
How it works
- Adds the
specify7submodule tosys.path. - Injects
config.local_specify_settingsintosys.modulesasspecifyweb.settings.local_specify_settings. - Calls
django.setup().
Writing a Script
Start your script with:
import bootstrap
bootstrap.setup()
from specifyweb.specify.models import Collection, Accession
# Now you can use the ORM!
print(Collection.objects.count())