Skip to content

A complete CRUD application using Django ORM, following Python standards and PEP-8 guidelines. It implements Create, Read, Update, and Delete operations with seamless database interactions. Designed for simplicity, it provides a step-by-step approach to setting up an ORM, storing, retrieving, and managing data efficiently in a Django backend.

Notifications You must be signed in to change notification settings

ashishkumar30/Django_CURD_ORM_Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

API testing and Project Structure/Flow

This guide explains how to test API endpoints using Postman. The API supports CRUD (Create, Read, Update, Delete) operations on a dataset.


Created by: Ashish kumar | github: https://github.com/ashishkumar30

**Data is already in Databse

πŸš€ The logger is activated in this setup. Please check the logs in the logfile at logs/gloroots_app.log

πŸš€ Please find attached a screenshot of the API testing and response in the Image folder.

Django Project Details

Project Name: gloroots

Project Structure:

β”œβ”€β”€ app_crud_operations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ admin.py
β”‚   β”œβ”€β”€ apps.py
β”‚   β”œβ”€β”€ crud_controller.py
β”‚   β”œβ”€β”€ migrations
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ response_json.py
β”‚   β”œβ”€β”€ serializers.py
β”‚   β”œβ”€β”€ tests.py
β”‚   β”œβ”€β”€ urls.py
β”‚   β”œβ”€β”€ views.py
β”œβ”€β”€ db.sqlite3
β”œβ”€β”€ gloroots
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ asgi.py
β”‚   β”œβ”€β”€ settings.py
β”‚   β”œβ”€β”€ urls.py
β”‚   β”œβ”€β”€ wsgi.py
β”œβ”€β”€ logs
β”‚   β”œβ”€β”€ gloroots_app
β”‚   └── gloroots_app.log
β”œβ”€β”€ manage.py
└── test.py

Setting up the Project

1️⃣ Activate Virtual Environment (if Available)

python -m venv venv  # Create a virtual environment
source venv/bin/activate  # Activate on macOS/Linux
venv\Scripts\activate  # Activate on Windows

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Run the Django Server

python manage.py runserver 8000

4️⃣ Run test.py for Backend CRUD Testing

python test.py

Alternatively, you can manually test endpoints using Postman.


Prerequisites

  • Install Postman
  • Ensure the API server is running at http://127.0.0.1:8000

API Endpoints

1️⃣ CREATE (POST)

  • URL: http://127.0.0.1:8000
  • Method: POST
  • Headers:
    • Content-Type: application/json
    • unloc: unlocs
  • Body: Raw JSON from GitHub Data

Example Request Body:

{
  "AEAJM": {
    "name": "Ajman",
    "city": "Ajman",
    "country": "United Arab Emirates",
    "coordinates": [55.5136433, 25.4052165],
    "province": "Ajman",
    "timezone": "Asia/Dubai",
    "unlocs": ["AEAJM"],
    "code": "52000"
  }
}

Example Response:

{
  "Status_code": 201,
  "Status": "Success",
  "Message": "New Data Created",
  "Data": [{
    "un_location_code_id": "AEAJM",
    "name": "Ajman",
    "city": "Ajman",
    "country": "United Arab Emirates",
    "coordinates": [55.5136433, 25.4052165],
    "province": "Ajman",
    "timezone": "Asia/Dubai",
    "code": "52000",
    "unlocs": ["AEAJM"]
  }]
}

2️⃣ READ (GET)

  • URL: http://127.0.0.1:8000?unloc=AOSZA
  • Method: GET
  • Headers:
    • Content-Type: application/json
    • unloc: XLDSSS

Example Response:

{
  "XLDSSS": {
    "name": "ASHISH",
    "city": "ASHISH",
    "country": "United Arab Emirates",
    "coordinates": [55.5136433, 25.4052165],
    "province": "Ajman",
    "timezone": "Asia/Dubai",
    "unlocs": ["AEAJM"],
    "code": "52000"
  }
}
  • Response: Returns requested data based on unloc in headers.
  • Response: Returns all data if unloc is not passed.

3️⃣ UPDATE (PATCH)

  • URL: http://127.0.0.1:8000?unloc=AEDXB
  • Method: PATCH
  • Headers:
    • Content-Type: application/json
    • unloc: AEDXB

Example Request Body:

{
  "AEDXB": {
    "name": "ASHISH",
    "city": "ASHISH",
    "country": "United Arab Emirates",
    "coordinates": [55.5136433, 25.4052165],
    "province": "Ajman",
    "timezone": "Asia/Dubai",
    "unlocs": ["AEAJM"],
    "code": "52000"
  }
}

Example Response:

{
  "Status_code": 201,
  "Status": "Success",
  "Message": "Data inserted successfully",
  "Data": {
    "un_location_code_id": "AEDXB",
    "name": "ASHISH",
    "city": "ASHISH",
    "country": "United Arab Emirates",
    "coordinates": [55.5136433, 25.4052165],
    "province": "Ajman",
    "timezone": "Asia/Dubai",
    "code": "52000",
    "unlocs": ["AEAJM"]
  }
}

4️⃣ DELETE (DELETE)

  • URL: http://127.0.0.1:8000?unloc=ESCAR
  • Method: DELETE
  • Headers:
    • unloc: AEDXB

Example Response:

{
  "Status_code": 204,
  "Status": "Success",
  "Message": "Location with UN location 'ESCAR' deleted successfully",
  "Data": null
}

About

A complete CRUD application using Django ORM, following Python standards and PEP-8 guidelines. It implements Create, Read, Update, and Delete operations with seamless database interactions. Designed for simplicity, it provides a step-by-step approach to setting up an ORM, storing, retrieving, and managing data efficiently in a Django backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages