#This is a sandbox for Elasticksearch, Django, Postgres and Reactjs
requirements
+ python3.5
let us create backend project
django-admin startproject backend
then create database and user with privileges, for this you can run script scripts/create-db.sh
or connect to database management system and do it like I did in Postgres
psql
CREATE USER user171030 WITH PASSWORD 'user171030';
ALTER ROLE user171030 SET client_encoding TO 'utf8';
ALTER ROLE user171030 SET default_transaction_isolation TO 'read committed';
ALTER ROLE user171030 SET timezone TO 'UTC';
ALTER USER user171030 CREATEDB;
CREATE DATABASE user171030;
GRANT ALL PRIVILEGES ON DATABASE user171030 TO user171030;
and now write down connect to database in django app settings backend/backend/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'user171030',
'USER': 'user171030',
'PASSWORD': 'user171030',
'HOST': 'localhost',
'PORT': '5432'
}
}
cd backend
python manage.py migrate
let's check our backend is working!!!
python manage.py runserver
rememeber names of our packages in requirements.txt
pip freeze > requirements.txt
opposite command, load packages from requirements.txt
pip install -r requirements.txt
cd backend
pip install coreapi djangorestframework \
djangorestframework-simplejwt
change install apps in settings.py
INSTALLED_APPS = [
...
'rest_framework',
]
# Rest Framework
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
}
now let us make some changes in urls.py
(have a look in git repo)
Now start up server!
./manage.py runserver
cd backend && ./manage.py startapp app_log
in file app_log/models.py
create model
add app in backend/settings.py
INSTALLED_APPS = [
...
'app_log',
]
TODO add description
mkdir -p apps/user_settings
./manage.py startapp user_settings apps/user_settings
if elastic_settings.json is in fixtures dir
./manage.py loaddata elastic_settings
python manage.py migrate ${APPNAME} zero
python manage.py migrate ${APPNAME}
./manage.py loaddata attributes.json
pip install django-cors-headers
than add to settings.py
INSTALLED_APPS = [
...
'corsheaders',
...
]
CORS_ORIGIN_ALLOW_ALL = True
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
...
]
run all tests
./manage.py test
run tests from app
./manage.py test apps.data_graph
run tests module
./manage.py test apps.data_graph.tests.DataGraphModelsTest
run test method
./manage.py test apps.data_graph.tests.DataGraphModelsTest.test_data
from the root of our project execute
mkdir frontend && cd frontend
create-react-app .
npm i --save bootstrap
npm i --save react-bootstrap
add routes
npm i --save react-router-dom