A collection of classes and commands for automated command line scripting using Python.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.6 KiB

3 years ago
# Django
Summary: Work with Django management commands.
## Common Options for Django Commands
You will want to include `cd` to change to the project directory (where `manage.py` lives) and supply `venv` to load the virtual environment.
```ini
[collect static files]
django.static:
cd: /path/to/project/source
venv: ../python
3 years ago
```
## Automatic Conversion of Django Command Switches
1 year ago
Options provided in the steps file are automatically converted to command line switches.
3 years ago
```ini
[run database migrations]
django.migrate:
settings: tenants.example_com.settings
[dump some data]
1 year ago
django.dump: projects.Category
indent: 4
natural_foreign: yes
natural_primary: yes
3 years ago
```
1 year ago
`settings` becomes "--settings=tenants.example_com.settings". `indent` becomes "--indent=4". `natural_foreign` and `natural_primary` become "--natural-foreign" and "--natural-primary" respectively.
3 years ago
## Available Commands
### check
```ini
[run django checks]
django.check:
stop: yes
```
### collectstatic
Alias: static
Collect static files.
```ini
[collect static files]
django.static:
3 years ago
```
### createsuperuser
Create a superuser account.
```ini
[create the root user account]
django.createsuperuser: root
email: root@example.com
3 years ago
```
### dumpdata
Alias: dump
3 years ago
Dump fixture data.
1 year ago
- `target` (str): Required. The name of the app or `app.Model`.
- `format` (str): `json` (default) or `xml`.
- `path` (str): The path to the output file. When a model is provided, this defaults to `fixtures/app/model.json`. Otherwise, it is `fixtures/app/initial.json`.
3 years ago
```ini
[dump project data]
django.dump: projects
3 years ago
[dump project categories]
django.dump: projects.Category
3 years ago
path: local/projects/fixtures/default-categories.json
3 years ago
```
### loaddata
Alias: load
3 years ago
Load fixture data.
3 years ago
1 year ago
- `target` (str): Required. The name of the app or `app.Model`.
- `format` (str): `json` (default) or `xml`
- `path` (str): The path to the JSON file. When a model is provided, this defaults to `fixtures/app/model.json`. Otherwise, it is `fixtures/app/initial.json`.
3 years ago
```ini
[load project categories]
django.load: projects
path: local/projects/fixtures/default-categories.json
3 years ago
```
### migrate
3 years ago
Run database migrations.
3 years ago
```ini
[run database migrations]
django.migrate:
stop: yes
3 years ago
```
## Custom or Ad Hoc Commands
It is possible to work with any Django management command provided the parameters may be specified as a switch.
```ini
[run any django command]
django: command_name
1 year ago
option_one: asdf
option_two: 1234
option_three: yes
3 years ago
```
1 year ago
This will generate a statement like:
```bash
1 year ago
./manage.py command_name --option-one="asdf" --option-two=1234 --option-three
1 year ago
3 years ago
```