The app development documentation assumes a local setyp on a UNIX like system,while untested development on windows should be supported provided you adapt the process for a windows system.
We use a local install of postgresql for new dB development to avoid breaking upstream development and prod envs.
Postgresql is available here We are using version 15 to align with the current prod db version.
In order to promote env isolation we use virtualenv to create a unique python env for this application.
virtualenv is available here if you do not have it installed.
Clone the repo:
git clone git@github.com:bovinehero/battletech-inventory.git
Create a Python 3.9.6 environment
cd battletech-inventory
python3 -m virtualenv --python=python3.9.6 .venv
Activate the environment
source .venv/bin/activate
The requirements.txt specifies psycopg2 as a dependency. When installing on certain environments psycopg2 needs the posgresql __pg_config__ in it's PATH, so either make sure to add it to your venv or export it prior to installing the requirments. Example for MacBook on the PostgreSQL default install location:
export PATH=/Library/PostgreSQL/15/bin/:$PATH
Missing this step will cause the pip execution to fail if the binary can't be found.
Install the app dependencies
pip install -r requirements.txt
Provided you have a dev environment set up as below the following can be used to set up a new local dB db.sqlite3 for the web app:
python manage.py migrate
python manage.py createsuperuser
The convention for the repo is to use an env.py at the repository root to manage the env variables when using a full install
import os
# env variables
os.environ["DATABASE_URL"] = 'postgres://'
os.environ["SECRET_KEY"] = ''
os.environ["CLOUDINARY_URL"] = 'cloudinary://'
os.environ["DEBUG"] = "TRUE"
os.environ["ALLOWED_HOST"] = "xxx-xxx-xxx.herokuapp.com"
# local db superuser and pass
super_user = ''
super_pass = ''
When deployed on a managed compute platform (like heroku) use ENV variables injected into the container creation process during the deployment/provisioning.
Performing the above actions creates the basic file structure used in the repo and gives us a local sqlite dB to play with.
the db.sqlite3 file is not contained in the downloadable repo, it will need to be re-created manually.
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
The default secret key for Django is insecure, to create a new one for env.py run the following in your venv:
python manage.py shell
Import the django secrets module and create a new key:
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
Paste the result in your env.py file like so:
os.environ["SECRET_KEY"] = 'django-example-^)3iq0)e@#$25%$e_8l_e5(rj&szl=f(jq^m628yx+k2_lcp27'