This Django project provides a CRUD API for managing purchase orders, suppliers, and line items. The API is built using Django, Django Rest Framework (DRF), and PostgreSQL.
- Fields:
name
: Stringemail
: Email field
- Fields:
item_name
: Stringquantity
: Positive integerprice_without_tax
: Decimal fieldtax_name
: Stringtax_amount
: Decimal fieldline_total
: Calculated field (quantity * price_without_tax).
- Fields:
supplier
: Foreign key to Supplier.order_time
: Date and timeorder_number
: Positive integertotal_quantity
: Calculated field (sum of quantities of line items).total_amount
: Calculated field (sum of line_total of line items).total_tax
: Calculated field (sum of tax_amount of line items).
- List and Create:
GET
andPOST
requests to/api/purchase/orders/
- Retrieve, Update, and Delete:
GET
,PUT
, andDELETE
requests to/api/purchase/orders/<int:id>/
- Python 3.x
- Pip (Python package installer)
- PostgreSQL
-
Clone the repository:
git clone https://github.com/your-username/purchase_order_project.git
-
Navigate to the project directory:
cd purchase_order_project
-
Create a virtual environment (optional but recommended):
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On Unix or MacOS:
source venv/bin/activate
-
-
Install project dependencies:
pip install -r requirements.txt
-
Create a PostgreSQL database for the project.
You can create a free tier postgresql instance from https://neon.tech/ OR use a local postgresql installation
-
Update the database settings in
purchase_order_project/settings.py
:- For local PostgreSQL installation
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'your_database_name', 'USER': 'your_database_user', 'PASSWORD': 'your_database_password', 'HOST': 'localhost', 'PORT': '5432', } }
- For neon.tech PostgreSQL instance
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'your_database_name', 'USER': 'your_database_user', 'PASSWORD': 'your_database_password', 'HOST': '******.aws.neon.tech', 'PORT': '5432', 'OPTIONS': {'sslmode': 'require'}, } }
- For local PostgreSQL installation
Apply the initial database migrations:
python manage.py makemigrations
python manage.py migrate
**By default a migrated neon.tech postgress instance is used, you do not need to apply the above migrations if you are using that.
Start the Django development server:
python manage.py runserver
The API will be accessible at http://127.0.0.1:8000/
.
-
Swagger: Open
http://127.0.0.1:8000/swagger/
in your web browser. -
ReDoc: Open
http://127.0.0.1:8000/redoc/
in your web browser.
To run the unit tests:
python manage.py test
To auto-generate the OpenAPI spec using Django Spectacular:
python manage.py spectacular --file schema.yml
This will create a file named schema.yml
containing the OpenAPI spec.
Import the PurchaseOrderProject.postman_collection.json in Postman