Simple Example for REST Services With Django Rest Framework
Create the Python Virtual environment and clone the project and follow the below steps. Installing
$ pip install -r requirements.txt
$ pip install psycopg2
Configuration
Configure the db with postgres in settings. Create the tables as shown in the models. Run the migrations as shown below. Syncdb is deprecated from the version 1.9.
Database
Use the rest.sql for creating database and tables.
Run Migration
$ python manage.py makemigration
Run Migrate
$ python manage.py migrate
Run Server
$ python manage.py runserver
By running following Url it will throws the error. It is related to foreign key. So first post the data as show in the POST data Section.
Rest URL/ GET URL
http://127.0.0.1:8000/master/users/
POST Data
$ curl -X POST http://127.0.0.1:8000/master/users/ -d '{"id":"1","repayment_type_name":"MANUAL", "fk_status":"1","last_modified_date":"2016-01-12 00:00:00+05:30","last_modified_by":"1"}' -H "Content-Type: application/json"
GET URL for single resource
http://127.0.0.1:8000/master/users/1/
Delete resource
curl -X DELETE http://127.0.0.1:8000/master/users/1/