- Install git:
sudo apt-get install -y git - Clone or download this repo.
- Install pip and vitualenv:
sudo apt-get install -y virtualenv
sudo apt-get install -y python3-pip - Create a virtual environment:
virtualenv -p python3 ~/.virtualenvs/managementEnv - Activate the virtual environment:
source ~/.virtualenvs/managementEnv/bin/activate - Install requirements in the virtualenv:
pip3 install -r requirements.txt
- Install components for Ubuntu:
sudo apt-get update
sudo apt-get install python-dev libpq-dev postgresql postgresql-contrib - Switch to postgres (PostgreSQL administrative user):
sudo su postgres - Log into a Postgres session:
psql - Create database with name blockwork:
CREATE DATABASE blockwork; - Create a database user which we will use to connect to the database:
CREATE USER blockwork_user WITH PASSWORD 'blockwork_pass'; - Modify a few of the connection parameters for the user we just created:
ALTER ROLE blockwork_user SET client_encoding TO 'utf8';
ALTER ROLE blockwork_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE blockwork_user SET timezone TO 'UTC';
ALTER USER blockwork_user CREATEDB; - Give our database user access rights to the database we created:
GRANT ALL PRIVILEGES ON DATABASE blobwork TO blobwork_user; - Exit the SQL prompt and the postgres user's shell session:
\qthenexit - Activate the virtual environment:
source ~/.virtualenvs/managementEnv/bin/activate - Make Django database migrations:
python manage.py makemigrations
then:python manage.py migrate
- Create an admin user:
python manage.py createsuperuser - Run the project locally:
python manage.py runserver - Navigate to:
http://localhost:8000/admin/
Method: GET
Endpoint: /product/
Description: List all products from the database
Method: POST
Endpoint: /product/
Payload:
{ "title": "product name", "product_code": "product code", "price": product price, "quantity": product quantity, "categories": [ 1,2 ] }
Description: Create new product in the database
Method: GET
Endpoint: /product/<product ID>/
Description: Get product in detail from the database
Method: PUT
Endpoint: /product/<product ID>/
Payload:
{ "title": "new product name", "product_code": "new product code", "price": new product price, "quantity": new product quantity, "categories": [ 1,2,3,4 ] }
Description: Update existing product in the database
Method: DELETE
Endpoint: /product/<product ID>/
Description: Delete product from the database
Method: GET
Endpoint: /category/
Description: List all categories from the database
Method: POST
Endpoint: /category/
Payload:
{ "name": "category name", "parent": 1 or can be null }
Description: Create new category in the database
Method: GET
Endpoint: /category/<category ID>/
Description: Get category in detail from the database
Method: PUT
Endpoint: /category/<category ID>/
Payload:
{ "name": "new category name", "parent": new parent ID or can be null }
Description: Update existing category in the database
Method: DELETE
Endpoint: /category/<category ID>/
Description: Delete category from the database
Method: GET
Endpoint: /category/<category ID>/children/
Description: Get specific category children from the database