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 .views import (
HomeView,
place_detail_view,
place_list_view,
PlaceDetailView,
PlaceListView,
SignUpView,
PlaceCreateView,
PlaceUpdateView,
@ -12,9 +12,9 @@ from .views import (
urlpatterns = [
path('', HomeView.as_view(), name='home'),
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/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
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')
template_name = 'signup.html'
def place_list_view(request,):
return render(request, 'place/place_list.html', {'place_list':Place.objects.all()})
class PlaceListView(IsAuthenticated, View):
def get(request):
context = {
'place_list': Place.objects.all()
}
return render(request, 'place/place_list.html', context)
def place_detail_view(request, pk):
return render(request, 'place/place_detail.html', {'place':Place.objects.get(pk=pk)})
class PlaceDetailView(IsAuthenticated, View):
def get(request, pk):
context = {
'place': Place.objects.get(pk=pk)
}
return render(request, 'place/place_detail.html', context)
class HomeView(View):
def get(self, request, *args, **kwargs):