https://github.com/roskakori/django-reporting-with-raw-sql
Code and slides for talk at PyCon Austria 2025
https://github.com/roskakori/django-reporting-with-raw-sql
django example reporting sql
Last synced: about 2 months ago
JSON representation
Code and slides for talk at PyCon Austria 2025
- Host: GitHub
- URL: https://github.com/roskakori/django-reporting-with-raw-sql
- Owner: roskakori
- License: mit
- Created: 2025-04-06T19:44:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-07T17:16:31.000Z (about 1 year ago)
- Last Synced: 2025-04-10T20:58:32.320Z (about 1 year ago)
- Topics: django, example, reporting, sql
- Language: Python
- Homepage:
- Size: 3.62 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Django reporting with raw SQL
This is a Python Django example application to show how to perform Django reporting by means of raw SQL and database views.
## Environment settings
The project requires an environment file named `.env` to know about the [PostgreSQL](https://www.postgresql.org/) database settings and the preferred default password for demo data.
For example:
```dotenv
# The default password for demo data.
MT_DEFAULT_PASSWORD="deMo.123"
# PotgreSQL database connection
MT_POSTGRES_HOST=localhost
MT_POSTGRES_PORT=5422
MT_POSTGRES_DATABASE=minitrack_local
MT_POSTGRES_USERNAME=minitrack_local
MT_POSTGRES_PASSWORD=${MT_DEFAULT_PASSWORD}
```
### PostgreSQL from docker container
By default, the application will connect to a local server running on port 5432 to a database `minitrack_local` with a user `minitrack_local` and the password `deMo.123`. The repository includes a `compose.yaml` which can be used with [Docker](https://www.docker.com/):
```bash
docker compose up
```
### Existing PostgreSQL server
If you already have access to an existing Postgre server, specify the settings in the `.env`.
## Project setup
The project requires [uv](https://docs.astral.sh/uv/).
To set up the project, run:
```bash
uv sync --group dev
```
In order to keep code clean even after your own modifications, activate the pre-commit hooks:
```bash
uv run pre-commit install --install-hooks
```
Next, apply the database migrations:
```bash
uv run python manage.py migrate
```
After that, create an admin user to log in. The fastest way for that is:
```bash
uv run python manage.py make_demo_admin
```
This adds an admin user named "admin" with the password specified with the environment variable `MT_DEFAULT_PASSWORD` (default: "deMo.123").
Alternatively, you can use the standard management command `createsuperuser` and specify all the details yourself:
```bash
uv run python manage.py createsuperuser --username admin
```
Then run the server
```bash
uv run python manage.py runserver
```
Now connect to and use the login from the `createsuperuser` from above.
You can use the admin UI to create and edit data.
To get you started quickly, create a few random demo data by running:
```bash
uv run python manage.py make_demo
```
## License
Copyright (c) 2025 Thomas Aglassinger. Distributed under the [MIT License](LICENSE).