backend-api for LENZ-API
-
Database
- Postgres SQL
- PG Admin 4
-
Django Version 4.2.4
-
Python Version 3.11
- python -m venv ./env
- this will create a virtual environment within the API directory called env
- to enact virtual environment run "./env/Scripts/activate" from main API directory
- note you must be in virtual environment in order to execute/run python and django commands.
- this will install any dependencies
- if you are adding more dependencies to the project, please update requirements.txt by running the command pip freeze > requirements.txt
- NEW UPDATE:
- update requirements.txt with the command pipreqs . --force
- assuming postgres is installed correctly, on the command line run createdb <db_name> to create a database within postgres, we will use this database name in the next steps
-
in the main API Directory, create a file called ".env"
-
we will use this as configuration for your API
-
add the following lines to the file:
- POSTGRES_DB=<db_name>
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=<db_password>
- POSTGRES_HOST=127.0.0.1
- The application will always have migrations to run from previous updates etc, to run migrations run the following command:
- python manage.py migrate
- this will update your database and tables, it is very important we do not delete migration files and try to push a single migration per pull request
- python manage.py migrate
- to update migrations or add new ones to the application, run the following command:
- python manage.py makemigrations
- to make migrations for a specific app to your database, run the following command:
- python manage.py <app_name> makemigrations
- to perform migrations on a specific database, run the following command:
- python manage.py makemigrations DATABASE=<db_name>
- a super user acts as an admin for the application as well as for django-admin, to create a super user run the following command:
- python manage.py createsuperuser
- follow the prompts to create the super user
- remember your password! django automatically hashes passwords in the database making it quite difficult to retrieve
- python manage.py createsuperuser
= command: - python manage.py collectstatic
- what it does:
- collects all the static files to run some of the various interfaces such as the admin interface
- python manage.py test apps..tests
- this will run the tests located in the tests directory of the app
- all tests must start with the word test in order for Django to discover it
- write tests in this file and in actions we will target them to run