This Django Rest Framework application provides endpoints to manage invoices and their associated details.
-
Clone the repository:
git clone https://github.com/your_username/invoice-management-api.git cd invoice-management-api
-
Create a virtual environment and activate it:
python -m venv venv # For Windows: venv\Scripts\activate # For Unix or MacOS: source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
-
Run database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
- URL:
/invoices/
- HTTP Methods: GET, POST
- Description: Endpoint to list all invoices or create a new invoice.
- Payload Example (POST):
{ "date": "2023-12-18", "customer_name": "Test Customer", "details": [ { "description": "Test Description", "quantity": 5, "unit_price": 10, "price": 50 } // Add more details if needed ] }
- URL:
/invoices/<int:pk>/
- HTTP Methods: GET, PUT, DELETE
- Description: Endpoint to retrieve, update, or delete a specific invoice.
The project includes comprehensive tests to ensure the functionality of the API endpoints. To run tests:
python manage.py test your_app_name
The application consists of two Django models:
Invoice
: Fields include Date and Customer Name.InvoiceDetail
: Fields include Invoice (ForeignKey), Description, Quantity, Unit Price, and Price.
Serializer classes are defined to transform model instances into JSON representations and vice versa.
InvoiceSerializer
: Handles serialization and deserialization of Invoice objects.InvoiceDetailSerializer
: Handles serialization and deserialization of InvoiceDetail objects.
Views are implemented using Django Rest Framework's generic views:
InvoiceListCreateView
: Handles listing and creation of Invoice instances.InvoiceDetailView
: Handles retrieval, update, and deletion of specific Invoice instances.
URL patterns are defined to map views to specific endpoints:
/invoices/
: Maps toInvoiceListCreateView
for listing and creation of invoices./invoices/<int:pk>/
: Maps toInvoiceDetailView
for retrieval, update, and deletion of specific invoices.