views.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.contrib.auth.forms import AuthenticationForm
  2. from django.contrib.auth.views import LoginView
  3. from django.shortcuts import render
  4. from django.urls import reverse_lazy
  5. from django.views.generic import ListView, CreateView, UpdateView
  6. from .models import *
  7. from .forms import *
  8. class Index(ListView):
  9. model = Service
  10. template_name = 'index.html'
  11. paginate_by = 5
  12. def get_queryset(self):
  13. return Service.objects.order_by('-date')
  14. def index(self):
  15. return render(self, 'index.html')
  16. class AllService(ListView):
  17. def all(self):
  18. return render(self, 'all.html')
  19. class Registration(CreateView):
  20. form_class = RegistrationForm
  21. template_name = 'user/registration.html'
  22. success_url = reverse_lazy('login')
  23. def registration(self):
  24. return render(self, 'user/registration.html')
  25. class LoginView(LoginView):
  26. form_class = AuthenticationForm
  27. template_name = 'user/login.html'
  28. success_url = reverse_lazy('profile')
  29. class Profile(UpdateView):
  30. model = User
  31. fields = ['username', 'name', 'surname', 'avatar']
  32. success_urls = reverse_lazy('profile')
  33. template_name = 'user/profile.html'