from django.urls import reverse_lazy from django.views.generic import ListView, CreateView, UpdateView, DeleteView from .models import Shop from .forms import ShopForm class ShopListView(ListView): """Список всех магазинов""" model = Shop template_name = 'shops/shop_list.html' context_object_name = 'shops' paginate_by = 20 def get_queryset(self): """Показываем только активные магазины по умолчанию""" queryset = super().get_queryset() return queryset.filter(is_active=True) class ShopCreateView(CreateView): """Создание нового магазина""" model = Shop form_class = ShopForm template_name = 'shops/shop_form.html' success_url = reverse_lazy('shops:shop_list') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = 'Создать магазин' context['button_text'] = 'Создать' return context class ShopUpdateView(UpdateView): """Редактирование магазина""" model = Shop form_class = ShopForm template_name = 'shops/shop_form.html' success_url = reverse_lazy('shops:shop_list') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = f'Редактировать: {self.object.name}' context['button_text'] = 'Сохранить' return context class ShopDeleteView(DeleteView): """Удаление магазина""" model = Shop template_name = 'shops/shop_confirm_delete.html' success_url = reverse_lazy('shops:shop_list')