DRF Websocket Django Backend
Instructions to run
- Clone the repository.
- Create a new Python 3 virtual environment using
virtualenv -p python3 venv
. If you don't havevirtualenv
installed then install it first usingpip3 install virtualenv
. - Activate the virtual environment using
source venv/bin/activate
. - Install requirements using
pip install -r requirements.txt
. - This project uses postgresql as database, before running the server, a postgres db needs to be setup. Run the following commands to setup a new database for the project.
sudo su - postgres
psql
CREATE DATABASE projectdb;
CREATE USER projectdbuser WITH PASSWORD 'projectdbpassword';
ALTER ROLE projectdbuser SET client_encoding TO 'utf8';
ALTER ROLE projectdbuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE projectdbuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE projectdb TO projectdbuser;
\q
exit
- Proceed to step 8 if you created database, user and password with values provided in commands above. Head over to
activate
file of your virtual environment present at<virtualenvironment>/bin/activate
, in this casevenv/bin/activate
and add the following environment variables at the end of the file. After adding the values deactivate the virtual environment usingdeactivate
command and activate again usingsource venv/bin/activate
export DBNAME="database name"
export DBUSER="database user"
export DBPASSWORD="database user's password"
- Migrate the database using
python manage.py migrate
- The raw restaurant data is in
hours.csv
. To process the raw data runpython dataloader.py
which will createfinalhours.csv
, one instance offinalhours.csv
is already present in the repository. - Load the data in the database using
python manage.py importdata
. You will see when the loading is completed, it generally takes almost 1 minute. - Create a superuser using
python manage.py createsuperuser
- Run the server using
python manage.py runserver
- Use keyboard interrupt
Ctrl + C
to stop the server. - For subsequent runs, just activate the virtual environment and run the server using
python manage.py runserver
. - Admin panel can be accessed at
/admin
.
Technologies Used:
- Python3
- Django
- Django Channels (websocket support for realtime updates)
- Django Rest Framework (for creating REST API's)
- Django Rest Knox (for JWT Token authentication)
- PostgreSQL Database
License
MIT