Django + drf + django-filter DB in postgresql Django configurations for settings file Common practice middlewares (timezones, querycount)
-
Python virtual environment:
We are using poetry to manage the projects dependencies.
Install Poetry - https://python-poetry.org/docs/#installation -
Get the code:
Clone this projectgit clone still_missing
-
Install dependencies:
enter projects directory and install dependencies using Poetry. Poetry will look for pyproject.toml filecd learning_django poetry install
And enter the virtual env created by Poetry:
poetry shell
From this point in the setup you should run the commands while you are inside the virtual env / poetry shell
-
Database:
We are currently using postgres. You need to set up a user,- After you have installed postgres, enter postgres cli client:
sudo su - postgres psql
- create a database, a user and a role
CREATE DATABASE learning_django_db; CREATE USER learning_django_user WITH PASSWORD 'learning_django_pass'; ALTER ROLE learning_django_user SET client_encoding TO 'utf8'; GRANT ALL PRIVILEGES ON DATABASE learning_django_db TO learning_django_user; ALTER ROLE learning_django_user CREATEDB;
- If PostgreSQL version is 15+
\c learning_django_db GRANT ALL ON SCHEMA public TO learning_django_user;
-
to exit postgres cli:
Ctrl+D
and then exit superuser shell
exit
-
Now you can migrate the data:
python manage.py migrate
-
Create a superuser for yourself to start working
python manage.py createsuperuser
-
Run the dev server
python manage.py runserver
poetry run python manage.py test
Ready to run as container (see dockerfile). Environment is determined by DJANGO_CONFIGURATION env variable which maps to class in settings.py. Note that in non local dev environments DEBUG=False so django won't magically serve statics You can use Nginx for that (before the django service, see, the nginx.conf for a reference) or install whitenoise and add it as a middleware. This is a common pattern for PAAS deployments
e.g when you work on the frontend
docker-compose up
First run would be quite long because of docker building
Postgres has some issues currently with start order, so if you see errors in the logs, just restart the compose a few times until it work
Depends on where you run, we support an initial github actions CI out of the box -declared here and a full amazon environment with codebuild buildspec file
- Django nested inlines for "nesting inlines" in the admin
- Celery for async, scheduled or "out of request/response cycle" behavior
- django admin reorder to customize the admin further
With ruff, not automated yet as part of CI
ruff check . --fix
ruff format