Converted last function-based views into class-based-views.

This commit is contained in:
Marcus Scholz 2020-08-12 19:24:04 +02:00
parent 87efccf6c9
commit 759c42279d
2 changed files with 16 additions and 8 deletions

View File

@ -1,8 +1,8 @@
from django.urls import path from django.urls import path
from .views import ( from .views import (
HomeView, HomeView,
place_detail_view, PlaceDetailView,
place_list_view, PlaceListView,
SignUpView, SignUpView,
PlaceCreateView, PlaceCreateView,
PlaceUpdateView, PlaceUpdateView,
@ -12,9 +12,9 @@ from .views import (
urlpatterns = [ urlpatterns = [
path('', HomeView.as_view(), name='home'), path('', HomeView.as_view(), name='home'),
path('signup/', SignUpView.as_view(), name='signup'), path('signup/', SignUpView.as_view(), name='signup'),
path('place/<int:pk>/', place_detail_view, name='place_detail'), path('place/<int:pk>/', PlaceDetailView.as_view(), name='place_detail'),
path('place/create/', PlaceCreateView.as_view(), name='place_create'), path('place/create/', PlaceCreateView.as_view(), name='place_create'),
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'), path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'), path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'),
path('place/', place_list_view, name='place_list') path('place/', PlaceListView.as_view(), name='place_list')
] ]

View File

@ -45,11 +45,19 @@ class SignUpView(CreateView):
success_url = reverse_lazy('login') success_url = reverse_lazy('login')
template_name = 'signup.html' template_name = 'signup.html'
def place_list_view(request,): class PlaceListView(IsAuthenticated, View):
return render(request, 'place/place_list.html', {'place_list':Place.objects.all()}) def get(request):
context = {
'place_list': Place.objects.all()
}
return render(request, 'place/place_list.html', context)
def place_detail_view(request, pk): class PlaceDetailView(IsAuthenticated, View):
return render(request, 'place/place_detail.html', {'place':Place.objects.get(pk=pk)}) def get(request, pk):
context = {
'place': Place.objects.get(pk=pk)
}
return render(request, 'place/place_detail.html', context)
class HomeView(View): class HomeView(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):