Using the knowledge of the python training create a project.
This project is based on a diagram made in class and my choice was a Shop system (POS) and if there is time to continue to start on making the start of administrations modules trying to throw high to get a close start on a ERP.
The shop will be base on this module at first glance and it will be modified:
Models
- Users
- Products
- Orders
- Cart
- CartItems
- Catgeories
- OrderItems
- TODO: Define next models to be used
Setting Up Containers for Django Project
- Build DB container:
>docker-compose build db
- Bring DB container up:
>docker-compose up db
- Set DB container to run on background:
>docker-compose up -d db
- Set DB container to run on background:
- Build MIGRATIONS container:
>docker-compose build migration
- Build WEB container:
>docker-compose build web
- Create a Django Project:
>docker-compose run web django-admin startproject my_web
- Setup DB connection on settings.py file
- Run MIGRATIONS container to create db
>docker-compose up migration
- Run Web container to check if settings and db are working:
>docker-compose up web
- Create a Super User for Admin:
>docker-compose run web python manage.py createsuperuser
Helpfull Commands
- Create migrations for a specific app:
>docker-compose run migration python manage.py makemigrations <APP_NAME>
-
Build Docker Image:
>docker-compose build
-
Run Dokcer DB First to avoid problems with Django Web app running first:
>docker-compose up -d db
-
Run Docker Migrations if they exist:
>docker-compose build migration
-
Run Docker Web app:
>docker-compose up -d web
-
Otherwise you could just run:
>docker-compose up
or>docker-compose up -d
-
Change Settings file on the main project:
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
-
Edit ALLOWED_HOSTS, DATABASES and TEMPLATES like the next code:
ALLOWED_HOSTS = [ '*' ] TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [TEMPLATE_DIR,], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': 'db_password', 'HOST': 'db', 'PORT': 5432, } }
-
Next Server should be running on local on port 8000:
0.0.0.0:8000 127.0.0.1:8000 localhost:8000
0.2
- [Antonio Carbajal][[email protected]]