mirror of
https://github.com/ada-dmitry/Project_WEB.git
synced 2026-09-24 08:00:20 +00:00
Add initial Django project structure with cleaning app
- Created .gitignore to exclude Python-generated files and virtual environments. - Added .python-version to specify Python version 3.13. - Implemented models for Client, Brigade, Service, Order, and CompletedWork. - Created Django admin configurations for managing models. - Added management command to seed the database with test data. - Created initial migrations for the models. - Developed views and templates for listing and detailing orders, clients, and brigades. - Set up URL routing for the cleaning app. - Configured Django settings and WSGI/ASGI entry points. - Added basic test structure in tests.py. - Included project metadata in pyproject.toml and uv.lock.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import random
|
||||
from datetime import date, timedelta, time
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from faker import Faker
|
||||
|
||||
from cleaning.models import Client, Brigade, Service, Order, CompletedWork
|
||||
|
||||
fake = Faker('ru_RU')
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Заполнить базу тестовыми данными'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
CompletedWork.objects.all().delete()
|
||||
Order.objects.all().delete()
|
||||
Service.objects.all().delete()
|
||||
Brigade.objects.all().delete()
|
||||
Client.objects.all().delete()
|
||||
|
||||
time_choices = ['morning', 'day', 'evening', 'any']
|
||||
clients = []
|
||||
for _ in range(12):
|
||||
client = Client.objects.create(
|
||||
full_name=fake.name(),
|
||||
address=fake.address().replace('\n', ', '),
|
||||
phone=fake.phone_number(),
|
||||
preferred_time=random.choice(time_choices),
|
||||
)
|
||||
clients.append(client)
|
||||
|
||||
specializations = [
|
||||
'Генеральная уборка',
|
||||
'Уборка после ремонта',
|
||||
'Мытьё окон',
|
||||
'Химчистка мебели',
|
||||
'Уборка офисов',
|
||||
]
|
||||
brigades = []
|
||||
for i, spec in enumerate(specializations):
|
||||
brigade = Brigade.objects.create(
|
||||
name=f'Бригада «{fake.last_name()}»',
|
||||
supervisor=fake.name(),
|
||||
employee_count=random.randint(2, 8),
|
||||
specialization=spec,
|
||||
)
|
||||
brigades.append(brigade)
|
||||
|
||||
services_data = [
|
||||
('Мытьё полов', 25.00, 0.5),
|
||||
('Мытьё окон', 80.00, 1.2),
|
||||
('Уборка ванной комнаты', 120.00, 2.0),
|
||||
('Пылесосинг ковров', 30.00, 0.8),
|
||||
('Мытьё сантехники', 90.00, 1.5),
|
||||
('Протирка мебели', 20.00, 0.3),
|
||||
('Чистка кухонной плиты', 150.00, 3.0),
|
||||
('Вынос мусора', 10.00, 0.1),
|
||||
('Мытьё зеркал', 40.00, 0.4),
|
||||
]
|
||||
services = []
|
||||
for name, price, duration in services_data:
|
||||
service = Service.objects.create(
|
||||
name=name,
|
||||
price_per_sqm=price,
|
||||
duration_per_sqm=duration,
|
||||
)
|
||||
services.append(service)
|
||||
|
||||
today = date.today()
|
||||
for i in range(25):
|
||||
order_date = today + timedelta(days=random.randint(-30, 15))
|
||||
start_hour = random.randint(8, 16)
|
||||
duration_hours = random.randint(2, 5)
|
||||
order = Order.objects.create(
|
||||
client=random.choice(clients),
|
||||
brigade=random.choice(brigades),
|
||||
date=order_date,
|
||||
start_time=time(start_hour, 0),
|
||||
end_time=time(start_hour + duration_hours, 0),
|
||||
)
|
||||
chosen_services = random.sample(services, k=random.randint(1, 4))
|
||||
for service in chosen_services:
|
||||
CompletedWork.objects.create(
|
||||
order=order,
|
||||
service=service,
|
||||
area=round(random.uniform(10, 80), 1),
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f'Готово: {Client.objects.count()} клиентов, '
|
||||
f'{Brigade.objects.count()} бригад, '
|
||||
f'{Service.objects.count()} услуг, '
|
||||
f'{Order.objects.count()} заказов.'
|
||||
))
|
||||
Reference in New Issue
Block a user