12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- from django.contrib.auth.decorators import login_required
- from django.contrib.auth.mixins import LoginRequiredMixin
- from django.contrib.auth.models import User
- from django.contrib.auth.views import LogoutView, LoginView
- from django.http import HttpResponseRedirect
- from django.shortcuts import render
- from django.urls import reverse_lazy
- from django.views.generic import TemplateView, ListView, DetailView, CreateView
- from .forms import RegistrationForm
- from .models import *
- # Create your views here.
- class HomePageView(ListView):
- template_name = 'base.html'
- context_object_name = 'product'
- model = Product
- def get_queryset(self):
- return Product.objects.all()[:5]
- class LogoutUserView(LoginRequiredMixin, LogoutView):
- template_name = 'registration/logout.html'
- success_url = reverse_lazy('base')
- class LoginUserView(LoginView):
- template_name = 'registration/login.html'
- success_url = reverse_lazy('profile')
- class ProductListView(ListView):
- model = Product
- template_name = 'service.html'
- context_object_name = 'products'
- class ProductDetailView(DetailView):
- model = Product
- template_name = 'detail_product.html'
- class RegistrationListView(CreateView):
- model = CustomUser
- form_class = RegistrationForm
- success_url = reverse_lazy('login')
- template_name = 'registration/register.html'
- class ProfileListView(ListView):
- model = Order
- context_object_name = 'profile'
- template_name = 'profile.html'
- def get_queryset(self):
- return Order.objects.filter(user=self.request.user)
|