A Django REST API application with CRUD operations, background tasks using Celery, and comprehensive features.
- Models: Orders, Customer, Seller, Product, PlatformApiCall
- Authentication: Token-based authentication
- CRUD Operations: Full CRUD for Orders and Products using Django REST Framework
- Permissions: Custom permissions and user restrictions
- API Logging: Automatic logging of all API calls via mixin
- Search & Filtering: Advanced search and filtering capabilities
- Background Tasks: Celery integration with scheduled tasks
- Excel Import: Management command to import products from Excel files
- Data Validation: Duplicate prevention and data validation
- name, mobile, User (Foreign Key)
- name, mobile, User (Foreign Key)
- name (unique), amount
- Validation for duplicate product creation
- customer (FK), seller (FK), products (ManyToMany), amount
- User (FK), requested_url, requested_data, response_data
POST /api/auth/token/- Get authentication token
GET /api/products/- List products (with search, filter, sorting)POST /api/products/- Create productGET /api/products/{id}/- Retrieve productPUT /api/products/{id}/- Update productDELETE /api/products/{id}/- Delete product
GET /api/orders/- List orders (with product filter, search)POST /api/orders/- Create orderGET /api/orders/{id}/- Retrieve orderPUT /api/orders/{id}/- Update orderDELETE /api/orders/{id}/- Delete order
GET /api/my-orders/- List customer's own orders only
GET /api/customers/- List customersPOST /api/customers/- Create customer
GET /api/sellers/- List sellersPOST /api/sellers/- Create seller
?search=<term>- Search products by name in orders?products=<id>- Filter orders by product?ordering=asc|desc|top5- Sort results
/api/orders/?search=laptop- Search orders containing "laptop"/api/orders/?products=1- Filter orders containing product ID 1/api/products/?ordering=top5- Get top 5 products by amount
pip install djangorestframework celery redis pandas openpyxl django-cors-headerspython manage.py makemigrations
python manage.py migratepython manage.py createsuperuserredis-serverpython manage.py runserver 0.0.0.0:3000celery -A django_project worker --loglevel=infocelery -A django_project beat --loglevel=info- Create user account through Django admin or API
- Get token:
POST /api/auth/token/with username/password - Include token in headers:
Authorization: Token <your-token>
python manage.py import_products path/to/your/file.xlsx- Column A: name (Product name)
- Column B: amount (Product amount)
The system automatically runs import task daily at 2:30 PM. You can also trigger manually:
from api.tasks import import_products_task
import_products_task.delay('path/to/file.xlsx')- Implemented using DRF TokenAuthentication
- Required for all API endpoints
- Full CRUD for Orders and Products
- Proper serializers with validation
- Automatically logs all API calls
- Captures request data, response data, and metadata
- Customer-only decorator for restricted endpoints
- Custom permissions for object-level access
- select_related: Used for Order list APIs to optimize user queries
- prefetch_related: Used for Product search in Order queries
- Search and filtering capabilities
- Product model validates unique names (case-insensitive)
- Excel import skips duplicates
- Ascending/Descending order
- Top 5 results option
- Customers can only view their own orders
- Decorator-based access control
- The application is configured to run on
0.0.0.0:3000 - CORS is configured for cross-origin requests
- Static and media files are properly configured
- Database uses SQLite for simplicity
- Broker: Redis
- Scheduled Task: Daily at 2:30 PM for product import
- Tasks: Product import from Excel files
Access the API using tools like:
- Django admin panel:
/admin/ - DRF browsable API:
/api/ - Postman or curl for API testing
- Token-based authentication
- CSRF protection
- User permission validation
- Input data validation
- SQL injection prevention through Django ORM
- Database query optimization with select_related and prefetch_related
- Pagination for large datasets
- Efficient filtering and search implementation