A Django REST Framework based guestbook application with optimized database queries and caching system.
- Create entries with user name, subject and message
- Automatic user creation for new names
- Paginated entry list (3 per page)
- User statistics
- Database query optimization
- Built-in caching system
- PostgreSQL database support
- Install requirements:
pip install -r requirements.txt
- Create
.env
file:
DJANGO_SECRET_KEY=your-secret-key
DJANGO_DEBUG=True
DB_NAME=guestbook_db
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=5432
- Run migrations:
python manage.py migrate
- Start development server:
python manage.py runserver
- URL:
/api/entries/
- Method: POST
- Content-Type: application/json
- Request Body:
{
"name": "user_name",
"subject": "entry_subject",
"message": "entry_message"
}
- URL:
/api/entries/
- Method: GET
- Query Parameters:
page
(optional) - Response Format:
{
"count": 10,
"page_size": 3,
"total_pages": 4,
"current_page_number": 1,
"links": {
"next": "http://api/entries/?page=2",
"previous": null
},
"entries": [
{
"user": "user_name",
"subject": "entry_subject",
"message": "entry_message"
}
]
}
- URL:
/api/users-data/
- Method: GET
- Response Format:
{
"users": [
{
"username": "user_name",
"last_entry": "subject | message"
}
]
}
- Name:
- Minimum length: 2 characters
- Maximum length: 255 characters
- Only letters, spaces, and hyphens allowed
- Cannot contain numbers
- Subject:
- Minimum length: 3 characters
- Maximum length: 255 characters
- Cannot contain inappropriate content
- Message:
- Minimum length: 10 characters
- General Rules:
- Message cannot be identical to subject
- Same message cannot be posted within 5 minutes
A ready-to-use Postman collection is available for testing the API. To use it:
- Open Postman application
- Click on "Import" button
- Select the file from
postman/Guestbook_API.postman_collection.json
- The collection includes pre-configured requests for all endpoints
- Indexes on foreign keys
- Composite indexes (user + created_at)
- select_related usage
- Database-level aggregation
- CORS protection
- Environment variables
- Debug mode disabled in production
- 5 minute cache duration
- LocMemCache implementation