7 Days Challenge to Push Your Hard Skill Using Django part 3: Which CBV or FBV should be used?

image from feldroy.com
from django.urls import reverse
from django.views.generic import ListView, DetailView, UpdateView
from .models import Tasting
class TasteListView(ListView):
model = Tasting
class TasteDetailView(DetailView):
model = Tasting
class TasteResultsView(TasteDetailView):
template_name = 'tastings/results.html'
class TasteUpdateView(UpdateView):
model = Tasting
from django.urls import path
from . import views
urlpatterns = [path(route='',view=views.TasteListView.as_view(), name='list'),path(route='<int:pk>/', view=views.TasteDetailView.as_view(), name='detail'),
path(route='<int:pk>/results/',view=views.TasteResultsView.as_view(), name='results'),
urlpatterns = [path('<int:pk>',DetailView.as_view(model=Tasting,template_name='tastings/detail.html'),name='detail'),path('<int:pk>/results/',DetailView.as_view(model=Tasting,template_name='tastings/results.html'),name='results'),


So the conclusion that we will get after understanding is that we choose to use the base view class or the base view function is based on the case we are going to work on, and the complexity of the view features that we create.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store