From adb13715992ff9cf46aac300eac5db971229e7d7 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 21 Jan 2021 10:29:35 +0000 Subject: [PATCH] add .env, wired database to settings, updated readme --- .gitignore | 3 +++ README.md | 32 ++++++++++++-------------------- back_latienda/settings.py | 25 ++++++++++++++++++++++--- example.env | 6 ++++++ requirements.txt | 8 ++++++++ 5 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 example.env create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 6769f52..020de9f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ # VSCode .vscode/ +# environment variables +.env + # Node artifact files node_modules/ dist/ diff --git a/README.md b/README.md index 39af52c..44b9240 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,21 @@ -# README # +# LaTiendaCOOP backend -This README would normally document whatever steps are necessary to get your application up and running. +This README aims to document functionality of backend as well as required steps to get it up and running. -### What is this repository for? ### +## Table of Contents -* Quick summary -* Version -* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) +- [First Steps](#first-steps) -### How do I get set up? ### -* Summary of set up -* Configuration -* Dependencies -* Database configuration -* How to run tests -* Deployment instructions +## First Steps -### Contribution guidelines ### +- Clone repository: +`git clone git@bitbucket.org:enreda/back-latienda.git` +- From inside the project's folder: +``` +python manage.py makemigrations core companies products history stats +python migrate -* Writing tests -* Code review -* Other guidelines +``` -### Who do I talk to? ### -* Repo owner or admin -* Other community or team contact \ No newline at end of file diff --git a/back_latienda/settings.py b/back_latienda/settings.py index f414238..4ff2df7 100644 --- a/back_latienda/settings.py +++ b/back_latienda/settings.py @@ -12,9 +12,16 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os +import dotenv + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# Get variables from .env +dotenv.read_dotenv( + dotenv=os.path.join(BASE_DIR, '.env'), + override=True + ) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ @@ -37,6 +44,13 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + + 'core', + 'companies', + 'products', + 'history', + 'stats', + ] MIDDLEWARE = [ @@ -73,11 +87,16 @@ WSGI_APPLICATION = 'back_latienda.wsgi.application' # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases +# Databases configuration DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.getenv('DB_NAME'), + 'USER': os.getenv('DB_USER'), + 'PASSWORD': os.getenv('DB_PASSWORD'), + 'HOST': os.getenv('DB_HOST', 'localhost'), + 'PORT': os.getenv('DB_PORT', '5432'), + }, } diff --git a/example.env b/example.env new file mode 100644 index 0000000..29af674 --- /dev/null +++ b/example.env @@ -0,0 +1,6 @@ +# rename file to .env and populate fields accordingly +DB_HOST = 'localhost' +DB_PORT = '3306' +DB_NAME = '' +DB_USER = '' +DB_PASSWORD = '' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d7e94a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +Django==2.2.17 +djangorestframework==3.12.2 +djangorestframework-simplejwt==4.4.0 +factory-boy==3.1.0 +django-dotenv==1.4.2 +django-filter==2.4.0 +-e git://github.com/darklow/django-suit/@v2#egg=django-suit +django-cors-headers==3.5.0 \ No newline at end of file