Skip to content

Latest commit

Β 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PartyLand - Django Shop + Telegram Bot Integration

Integration of Django REST API e-commerce platform with Telegram delivery bot.

πŸš€ Quick Start

1. Start Django Server

Terminal 1 - Django:

./start_django.sh

Or manually:

cd Shop_site
source venv/bin/activate
python manage.py runserver

Django will be available at: http://localhost:8000

2. Start Telegram Bot

Terminal 2 - Bot:

./start_bot.sh

Or manually:

cd TG_bot
python main.py

3. Start Frontend (Optional)

Terminal 3 - Frontend:

cd frontend
npm install
npm run dev

Frontend will be available at: http://localhost:3000

πŸ“ Project Structure

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

🎯 What's Integrated

βœ… Completed

  • 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

🚧 In Progress

  • Full cart synchronization with Django
  • Order creation in Django
  • Image URL support for products

πŸ“‘ API Endpoints

Access the API documentation at:

Key Endpoints

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

βš™οΈ Configuration

Environment Variables

Set DJANGO_API_URL for the bot:

export DJANGO_API_URL="http://localhost:8000/api"

Bot Token

Get your bot token from @BotFather

Edit TG_bot/main.py:

bot = telebot.TeleBot("YOUR_BOT_TOKEN", parse_mode='HTML')

Admin Password

Edit TG_bot/main.py:

ADMIN_PASSWORD = "your_secure_password"

πŸ—„οΈ Database Models

Django Models

TelegramUser

  • telegram_id - Unique Telegram user ID
  • name, phone, language, birthday
  • is_admin - Admin flag
  • Timestamps

TelegramAddress

  • user - Foreign key to TelegramUser
  • address, latitude, longitude
  • Timestamps

Order (updated)

  • Supports both web users and telegram users
  • Added address and delivery_time fields
  • Links to appropriate user type

πŸ”§ Development

Running Migrations

cd Shop_site
source venv/bin/activate
python manage.py makemigrations
python manage.py migrate

Creating Superuser

cd Shop_site
source venv/bin/activate
python manage.py createsuperuser

Adding Products

  1. Go to http://localhost:8000/admin/
  2. Login with superuser
  3. Create Categories and Products

πŸ§ͺ Testing

  1. Start Django server: ./start_django.sh
  2. Start the bot: ./start_bot.sh
  3. Open Telegram and message your bot
  4. Use /start command
  5. Browse products (now from Django!)

πŸ“ Usage

Telegram Bot Commands

  • /start - Start/register
  • /admin - Admin menu (requires password)

Main Menu

  • πŸ› Π—Π°ΠΊΠ°Π·Π°Ρ‚ΡŒ - Make order
  • πŸ“¦ Мои Π·Π°ΠΊΠ°Π·Ρ‹ - View orders
  • βš™οΈ Настройки - Settings
  • ℹ️ О нас - About

Admin Features

  • βž• Add products
  • ✏️ Edit products
  • ❌ Delete products
  • πŸ“‹ List products

πŸ” How It Works

Product Flow

User β†’ Bot β†’ Django API β†’ Database
              ↓
         Display products

Order Flow

User β†’ Bot β†’ Local Cart β†’ Create Order β†’ Django API

πŸ› Troubleshooting

"Can't connect to Django"

  • Ensure Django server is running
  • Check DJANGO_API_URL environment variable
  • Verify port 8000 is available

"Products not showing"

Database errors

cd Shop_site
python manage.py migrate

πŸ“š Documentation

🀝 Contributing

  1. Make changes
  2. Test locally
  3. Update documentation
  4. Submit PR

πŸ“„ License

Project for learning and development purposes.

πŸŽ‰ Features

  • βœ… Bilingual support (Russian, Uzbek)
  • βœ… Product catalog from Django
  • βœ… Order management
  • βœ… Admin panel for products
  • βœ… Address management
  • βœ… Cart functionality
  • βœ… Fallback to local database

πŸ“ž Support

Check logs for issues:

  • Django: Server console
  • Bot: Bot console

πŸš€ Production Notes

Before deploying:

  1. Set DEBUG = False in Django settings
  2. Configure ALLOWED_HOSTS
  3. Use environment variables for secrets
  4. Use PostgreSQL instead of SQLite
  5. Set up HTTPS
  6. Configure proper logging
  7. Use process managers (systemd, supervisor)

🎯 Next Steps

  • 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! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages