Populate list data and other static model data on startup
Project description
edc-list-data
Populate list data and other static model data on Django startup.
To install add edc_list_data.apps.AppConfig to your INSTALLED_APPS, then create a list_data.py in the root of your app.
Most commonly used to populate M2M data known here as list_data. M2M field models should use the ListModelMixin.
The list models are populated using a post_migrate signal. Once everything is configured or after changes are made, you need to run python manage.py migrate.
For example:
class Antibiotic(ListModelMixin, BaseUuidModel):
class Meta(ListModelMixin.Meta):
pass
An example list_data.py:
from edc_constants.constants import OTHER
list_data = {
'my_lists_app.antibiotic': [
('flucloxacillin', 'Flucloxacillin'),
('gentamicin', 'Gentamicin'),
('ceftriaxone', 'Ceftriaxone'),
('amoxicillin_ampicillin', 'Amoxicillin/Ampicillin'),
('doxycycline', 'Doxycycline'),
('erythromycin', 'Erythromycin'),
('ciprofloxacin', 'Ciprofloxacin'),
(OTHER, 'Other, specify')
],
}
- Now run:
>>> python manage.py migrate
The list data will be populated in the order in which the list items are declared.
See also call to site_list_data.autodiscover and site_list_data.load_data called in edc_list_data.apps.AppConfig using a post_migrate signal.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for edc_list_data-0.3.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a84101a72296f3624c48f88760d200b2739079598e58dc84f0f2a33cffd73d |
|
MD5 | 21f937fda4684d3740ecf78738be1f78 |
|
BLAKE2b-256 | dcfd61c36320bbe3853fe2b86dfcda602c8a4fbf58a863f3b2aab4ea83ee2be9 |