Easily bundle example data with your django apps.
Install
$ pip install django_addexampledata
Setup
Add 'django_addexampledata' to INSTALLED_APPS.
Usage
django_addexampledata provides two Django management commands:
- addexampledata
Finds all apps with an exampledata.py, and runs appname.exampledata.add_exampledata() on these apps. See the howto below for more info.
- createexampleuser
Create an example user. See --help for the User attributes that can be set. Example:
python manange.py createexampleuser grandma --is-superusercreates a superuser named grandma with password set to test.
addexampledata howto
Add exampledata.py to the root of your Django app (in the same directory as models.py). Add an add_exampledata function to this module. Your exampledata.py may look something like this:
from models import Page
def add_exampledata():
aboutus = Page.objects.create(title="About us",
body="Hello cruel world")
contactinfo = Page.objects.create(title="Contact info",
body="Coming soon.",
parent=aboutus)
As long as your Django app is in INSTALLED_APPS, <appname>.exampledata.add_exampledata is run each time you run:
python manage.py addexampledata
addexampledata on specific apps
You can specify the apps that you want to add example data for as arguments for the command. Example:
python manage.py addexampledata myapp myotherapp
addexampledata adds the same data each time it runs!
You can solve this in two ways:
(reccommended) Add a make target or something similar (we use a Fabric action) to reset your example database and re-run addexampledata. Use this action whenever you change/add models or exampledata.
Check for existing items in add_exampledata() before inserting new data.
Metadata
Release files for django_addexampledata 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_addexampledata-1.0.tar.gz | 3.0 kB | Without provenance | Details for django_addexampledata-1.0.tar.gz |
Release files / django_addexampledata-1.0.tar.gz
| Download URL | django_addexampledata-1.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
457f5305799e0d8241a3b0766426d142a007acaa3875b46eb2fdafef56cbc6c3
|
|
BLAKE2b-256 checksum How to use checksums |
67ede35eb3d18ed53364321e92c8a8b7d28a330d503afb62aad226955f968523
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django_addexampledata 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.