Skip to content

vitaliwow/django-example

Repository files navigation

Project structure

The main django app is called core. It contains .env file for django-environ. For examples see src/core/.env.ci. Here are some usefully app-wide tools:

  • core.admin — app-wide django-admin customizations (empty yet), check out usage examples
  • core.test.api_client (available as api and anon fixtures within pytest) — a convinient DRF test client.

Django's user model is located in the separate users app.

Also, feel free to add as much django apps as you want.

Installing on a local machine

Running a project with docker (preferred method)
  1. Install docker and docker compose suitable for your operating system. official docker website
docker compose version

~ Docker Compose version v2.2.3
  1. Clone a project in /your_dir/

  2. Create a .env file and add variables as per "/your_dir/main/infra/.env.example"

cd /your_dir/main/  # go to main dir
touch .env  # create .env file
nano .env   # open the .env file and add variables as in .env.example
  1. Start project.
docker compose up --build -d
Run the project by installing all packages
This project requires python 3.11. Deps are managed by [Poetry](https://python-poetry.org/docs/).

Install requirements:

Install Poetry If you haven't already, you need to install Poetry, a tool for managing Python dependencies. You can find the installation guide at python-poetry.org.

Install Ruff If you haven't already, you need to install Ruff, a tool for linting code. You can find the installation guide at docs.astral.sh/ruff.

Run the server:

$ cd src && cp core/.ci.env core/.env  # default environment variables
$ ./manage.py migrate
$ ./manage.py createsuperuser
$ ./manage.py runserver

Testing(run it before pushing your code):

# run lint
$ make lint

# fix lint issues
$ make fmt

# run unit tests
$ make test

Development servers:

# run django dev server
$ ./manage.py runserver

Backend Code requirements

Style

  • Obey django's style guide.
  • Configure your IDE to use Ruff for checking your python code. To run our linters manualy, do make lint
  • Prefer English over your native language in comments and commit messages.
  • Commit messages should contain the unique id of issue they are linked to (refs #100500)
  • Every model, service and model method should have a docstring.

Code organisation

  • KISS and DRY.
  • Obey django best practices.
  • No logic is allowed within the views or serializers. Only services and models. When a model grows beyond 500 lines of code — go create some services.
  • Use PEP-484 type hints when possible.
  • Prefer composition to inheritance.
  • Never use signals or GenericRelations in your own code.
  • No l10n is allowed in python code, use django translation.

About

example app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages