views.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from django.contrib.auth.decorators import login_required
  2. from django.contrib.auth.mixins import LoginRequiredMixin
  3. from django.contrib.auth.models import User
  4. from django.contrib.auth.views import LogoutView, LoginView
  5. from django.http import HttpResponseRedirect
  6. from django.shortcuts import render
  7. from django.urls import reverse_lazy
  8. from django.views.generic import TemplateView, ListView, DetailView, CreateView
  9. from .forms import RegistrationForm
  10. from .models import *
  11. # Create your views here.
  12. class HomePageView(ListView):
  13. template_name = 'base.html'
  14. context_object_name = 'product'
  15. model = Product
  16. def get_queryset(self):
  17. return Product.objects.all()[:5]
  18. class LogoutUserView(LoginRequiredMixin, LogoutView):
  19. template_name = 'registration/logout.html'
  20. success_url = reverse_lazy('base')
  21. class LoginUserView(LoginView):
  22. template_name = 'registration/login.html'
  23. success_url = reverse_lazy('profile')
  24. class ProductListView(ListView):
  25. model = Product
  26. template_name = 'service.html'
  27. context_object_name = 'products'
  28. class ProductDetailView(DetailView):
  29. model = Product
  30. template_name = 'detail_product.html'
  31. class RegistrationListView(CreateView):
  32. model = CustomUser
  33. form_class = RegistrationForm
  34. success_url = reverse_lazy('login')
  35. template_name = 'registration/register.html'
  36. class ProfileListView(ListView):
  37. model = Order
  38. context_object_name = 'profile'
  39. template_name = 'profile.html'
  40. def get_queryset(self):
  41. return Order.objects.filter(user=self.request.user)