Initial commit: Django backend with Campaign, ContactUs, and Composition APIs
This commit is contained in:
135
README.md
Normal file
135
README.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# Zoneco ORG Backend API
|
||||
|
||||
A professional Django REST Framework backend for Zoneco ORG with PostgreSQL database.
|
||||
|
||||
## Features
|
||||
|
||||
- **Contact Us API**: Handle contact form submissions with name, email/phone, description, and category
|
||||
- **Composition API**: Manage compositions with name, description, and image
|
||||
- **Campaign API**: Manage campaigns with name, description, start/end times, and image
|
||||
- **RESTful API**: Full CRUD operations for all models
|
||||
- **CORS Enabled**: Configured for frontend integration
|
||||
- **Image Upload**: Support for image uploads with proper media handling
|
||||
- **Admin Panel**: Django admin interface for managing data
|
||||
|
||||
## Database Configuration
|
||||
|
||||
- **Database Name**: Zoneco_ORG
|
||||
- **User**: postgres
|
||||
- **Password**: postgres
|
||||
- **Host**: localhost
|
||||
- **Port**: 5432
|
||||
|
||||
## Installation
|
||||
|
||||
1. **Install Python dependencies:**
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
2. **Create PostgreSQL database:**
|
||||
```sql
|
||||
CREATE DATABASE "Zoneco_ORG";
|
||||
```
|
||||
|
||||
3. **Run migrations:**
|
||||
```bash
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
```
|
||||
|
||||
4. **Create superuser (optional):**
|
||||
```bash
|
||||
python manage.py createsuperuser
|
||||
```
|
||||
|
||||
5. **Run development server:**
|
||||
```bash
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
The API will be available at `http://localhost:8000/api/`
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Contact Us
|
||||
- `GET /api/contact-us/` - List all contacts
|
||||
- `POST /api/contact-us/` - Create new contact (public)
|
||||
- `GET /api/contact-us/{id}/` - Get specific contact
|
||||
- `PUT /api/contact-us/{id}/` - Update contact (authenticated)
|
||||
- `PATCH /api/contact-us/{id}/` - Partial update (authenticated)
|
||||
- `DELETE /api/contact-us/{id}/` - Delete contact (authenticated)
|
||||
- `GET /api/contact-us/by_category/?category={category}` - Filter by category
|
||||
|
||||
### Compositions
|
||||
- `GET /api/compositions/` - List all compositions
|
||||
- `POST /api/compositions/` - Create new composition (authenticated)
|
||||
- `GET /api/compositions/{id}/` - Get specific composition
|
||||
- `PUT /api/compositions/{id}/` - Update composition (authenticated)
|
||||
- `PATCH /api/compositions/{id}/` - Partial update (authenticated)
|
||||
- `DELETE /api/compositions/{id}/` - Delete composition (authenticated)
|
||||
|
||||
### Campaigns
|
||||
- `GET /api/campaigns/` - List all campaigns
|
||||
- `POST /api/campaigns/` - Create new campaign (authenticated)
|
||||
- `GET /api/campaigns/{id}/` - Get specific campaign
|
||||
- `PUT /api/campaigns/{id}/` - Update campaign (authenticated)
|
||||
- `PATCH /api/campaigns/{id}/` - Partial update (authenticated)
|
||||
- `DELETE /api/campaigns/{id}/` - Delete campaign (authenticated)
|
||||
- `GET /api/campaigns/active/` - Get active campaigns
|
||||
- `GET /api/campaigns/upcoming/` - Get upcoming campaigns
|
||||
- `GET /api/campaigns/ended/` - Get ended campaigns
|
||||
|
||||
## Models
|
||||
|
||||
### ContactUs
|
||||
- `name` (CharField): Name of the contact
|
||||
- `email_or_phone` (CharField): Email or phone number
|
||||
- `description` (TextField): Message description
|
||||
- `category` (CharField): Category (همکاری, فروش, پشتیبانی, درخواست مشاور, سایر)
|
||||
- `created_at` (DateTimeField): Creation timestamp
|
||||
- `updated_at` (DateTimeField): Last update timestamp
|
||||
|
||||
### Composition
|
||||
- `name` (CharField): Name of the composition
|
||||
- `description` (TextField): Description
|
||||
- `image` (ImageField): Composition image
|
||||
- `created_at` (DateTimeField): Creation timestamp
|
||||
- `updated_at` (DateTimeField): Last update timestamp
|
||||
|
||||
### Campaign
|
||||
- `name` (CharField): Campaign name
|
||||
- `description` (TextField): Campaign description
|
||||
- `start_time` (DateTimeField): Campaign start time
|
||||
- `end_time` (DateTimeField): Campaign end time
|
||||
- `image` (ImageField): Campaign image
|
||||
- `created_at` (DateTimeField): Creation timestamp
|
||||
- `updated_at` (DateTimeField): Last update timestamp
|
||||
|
||||
## Admin Panel
|
||||
|
||||
Access the Django admin panel at `http://localhost:8000/admin/` after creating a superuser.
|
||||
|
||||
## CORS Configuration
|
||||
|
||||
CORS is configured to allow requests from:
|
||||
- `http://localhost:5173` (Vite default)
|
||||
- `http://localhost:3000`
|
||||
- `http://127.0.0.1:5173`
|
||||
- `http://127.0.0.1:3000`
|
||||
|
||||
## Media Files
|
||||
|
||||
Uploaded images are stored in the `media/` directory:
|
||||
- Composition images: `media/compositions/`
|
||||
- Campaign images: `media/campaigns/`
|
||||
|
||||
## Development Notes
|
||||
|
||||
- The backend uses Django REST Framework for API endpoints
|
||||
- PostgreSQL is used as the database
|
||||
- Image uploads are handled via multipart/form-data
|
||||
- All models include proper indexing for performance
|
||||
- Serializers include validation and proper error handling
|
||||
- Viewsets provide both public read access and authenticated write access
|
||||
|
||||
Reference in New Issue
Block a user