Integration of Django REST API e-commerce platform with Telegram delivery bot.
Terminal 1 - Django:
./start_django.shOr manually:
cd Shop_site
source venv/bin/activate
python manage.py runserverDjango will be available at: http://localhost:8000
Terminal 2 - Bot:
./start_bot.shOr manually:
cd TG_bot
python main.pyTerminal 3 - Frontend:
cd frontend
npm install
npm run devFrontend will be available at: http://localhost:3000
PartyLand/
βββ Shop_site/ # π Django Backend
β βββ db.sqlite3 # ποΈ UNIFIED DATABASE
β βββ site_app/
β β βββ models.py # TelegramUser, TelegramAddress
β β βββ views.py # API views
β β βββ urls.py # API routes
β β βββ admin.py # Admin panel
β βββ site_proj/ # Django settings
β βββ requirements.txt # Python dependencies
β
βββ TG_bot/ # π€ Telegram Bot
β βββ main.py # Bot logic
β βββ db_orm.py # Django ORM integration
β βββ api_client.py # Django API client
β βββ keyboards.py # Bot keyboards
β βββ requirements.txt # Python dependencies
β
βββ frontend/ # βοΈ Next.js Frontend
β βββ src/
β β βββ app/ # Next.js App Router
β β βββ components/ # React components
β β βββ lib/ # API client & utils
β βββ package.json # Node dependencies
β βββ README.md # Frontend docs
β
βββ start_django.sh # Django startup
βββ start_bot.sh # Bot startup
βββ README.md # This file
- Unified Database - Single SQLite database for Django and Bot
- Django ORM - Bot uses Django models instead of SQL
- Next.js Frontend - Modern React frontend with TypeScript
- Django models for Telegram users and addresses
- REST API endpoints for Telegram bot
- API client in bot for Django communication
- Product fetching from Django API
- Type-safe ORM operations
- Automatic migrations
- Admin panel for managing users and products
- Frontend integrated with Django backend
- Full cart synchronization with Django
- Order creation in Django
- Image URL support for products
Access the API documentation at:
- Swagger: http://localhost:8000/swagger/
- ReDoc: http://localhost:8000/redoc/
- Django Admin: http://localhost:8000/admin/
GET /api/products/ # List products
GET /api/products/{id}/ # Product details
GET /api/telegram-users/{id}/ # Get/update telegram user
GET /api/telegram-addresses/ # List addresses
POST /api/telegram-addresses/ # Create address
Set DJANGO_API_URL for the bot:
export DJANGO_API_URL="http://localhost:8000/api"Get your bot token from @BotFather
Edit TG_bot/main.py:
bot = telebot.TeleBot("YOUR_BOT_TOKEN", parse_mode='HTML')Edit TG_bot/main.py:
ADMIN_PASSWORD = "your_secure_password"TelegramUser
telegram_id- Unique Telegram user IDname,phone,language,birthdayis_admin- Admin flag- Timestamps
TelegramAddress
user- Foreign key to TelegramUseraddress,latitude,longitude- Timestamps
Order (updated)
- Supports both web users and telegram users
- Added address and delivery_time fields
- Links to appropriate user type
cd Shop_site
source venv/bin/activate
python manage.py makemigrations
python manage.py migratecd Shop_site
source venv/bin/activate
python manage.py createsuperuser- Go to http://localhost:8000/admin/
- Login with superuser
- Create Categories and Products
- Start Django server:
./start_django.sh - Start the bot:
./start_bot.sh - Open Telegram and message your bot
- Use
/startcommand - Browse products (now from Django!)
/start- Start/register/admin- Admin menu (requires password)
- π ΠΠ°ΠΊΠ°Π·Π°ΡΡ - Make order
- π¦ ΠΠΎΠΈ Π·Π°ΠΊΠ°Π·Ρ - View orders
- βοΈ ΠΠ°ΡΡΡΠΎΠΉΠΊΠΈ - Settings
- βΉοΈ Π Π½Π°Ρ - About
- β Add products
- βοΈ Edit products
- β Delete products
- π List products
User β Bot β Django API β Database
β
Display products
User β Bot β Local Cart β Create Order β Django API
- Ensure Django server is running
- Check
DJANGO_API_URLenvironment variable - Verify port 8000 is available
- Check Django admin for products
- Visit http://localhost:8000/api/products/
- Check bot console logs
cd Shop_site
python manage.py migrate- Integration Guide - Detailed integration documentation
- Django Docs
- Telegram Bot API
- Django REST Framework
- Make changes
- Test locally
- Update documentation
- Submit PR
Project for learning and development purposes.
- β Bilingual support (Russian, Uzbek)
- β Product catalog from Django
- β Order management
- β Admin panel for products
- β Address management
- β Cart functionality
- β Fallback to local database
Check logs for issues:
- Django: Server console
- Bot: Bot console
Before deploying:
- Set
DEBUG = Falsein Django settings - Configure
ALLOWED_HOSTS - Use environment variables for secrets
- Use PostgreSQL instead of SQLite
- Set up HTTPS
- Configure proper logging
- Use process managers (systemd, supervisor)
- Complete cart sync with Django
- Full order creation in Django
- Image upload and display
- Category filtering
- API authentication
- Order status tracking
- Payment integration
Happy coding! π