django, ¿hay una mejor variante para usar el enfoque CBV en mi proyecto?

Lo siento por una pregunta tan larga y mi mal inglés. Terminé Python Crash Course, un libro de introducción a la programación de Eric Matthes. Después de eso, decidió continuar estudiando Django y descubrió que el método CBV es más aceptable para la creación de sitios. Reescribí a través del programa de capacitación de CBV del libro que fue escrito por funciones, pero todavía me siento un poco perdido con los métodos de CBV después de leer la documentación oficial. ¿Alguien podría decir si hay mucha codificación en mi variante CBV? ¿Y es posible hacerlo mejor?

Todas las variantes funcionan bien.

Aquí la variante de vistas de los libros con comentarios, inserté un comentario para entender qué hace el código:

from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.http import Http404
from .models import Topic, Entry
from .forms import TopicForm, EntryForm

# Create your views here.

def index(request):
    """Home page of Learning Log."""
    return render(request, 'learning_logs/index.html')

def more_inf(request):
    return render(request,'learning_logs/more_inf.html')

def topics(request):
    """List of topics"""
    public_topics = Topic.objects.filter(public=True).order_by('date_added')
    if request.user.is_authenticated:
        private_topics = Topic.objects.filter(owner=request.user).order_by('date_added')
        topics = public_topics | private_topics
    else:
        topics = public_topics
    
    context = {'topics': topics}
    return render(request, 'learning_logs/topics.html', context)

@login_required
def topic(request, topic_id):
    """Show one topic with details"""
    topic = get_object_or_404(Topic, id=topic_id)
    #Проверка того, что тема принадлежит текущему пользователю
    check_topic_owner(topic.owner, request)

    entries = topic.entry_set.order_by('-date_added')
    context = {'topic': topic, 'entries': entries}
    return render(request, 'learning_logs/topic.html', context)

@login_required
def new_topic(request):
    """Create new topic"""
    if request.method != 'POST':
        #data wasn't sent;create empty form
        form = TopicForm()
    else:
        #POST data sent; to process the data.
        form = TopicForm(data=request.POST)
        if form.is_valid():
            new_topic = form.save(commit=False)
            new_topic.owner = request.user
            new_topic.save()
            return redirect('learning_logs:topics')

    #Show empty or invalid form.
    context = {'form': form}
    return render(request, 'learning_logs/new_topic.html', context)

@login_required
def new_entry(request, topic_id):
    """Add new entry to the topic"""
    topic = get_object_or_404(Topic, id=topic_id)
    check_topic_owner(topic.owner, request)
    if request.method != 'POST':
        #data wasn't sent;create empty form
        form = EntryForm()
    else:
        #POST data sent; to process the data.
        form = EntryForm(data=request.POST)
        if form.is_valid():
            new_entry = form.save(commit=False)
            new_entry.topic = topic
            new_entry.save()
            return redirect('learning_logs:topic', topic_id=topic_id)

    #Show empty or invalid form.
    context = {'topic': topic, 'form': form}
    return render(request, 'learning_logs/new_entry.html', context)

@login_required
def edit_entry(request, entry_id):
    """Edit the current entry"""
    entry = get_object_or_404(Entry, id=entry_id)
    topic = entry.topic
    check_topic_owner(topic.owner, request)

    if request.method !='POST':
        #initial request; form was created by current data entries
        form = EntryForm(instance=entry)
    else:
        #POST data sent; to process the data.
        form = EntryForm(instance=entry, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('learning_logs:topic', topic_id=topic.id)

    context = {'entry': entry, 'topic': topic, 'form': form}
    return render(request, 'learning_logs/edit_entry.html', context)

def check_topic_owner(owner, request):
    if owner != request.user:
        raise Http404

Ahí está mi nueva variante CBV, también con slugs agregados y absolute_url: ¿Qué puedo mejorar allí? Gracias de antemano

from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import Http404
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from .models import Topic, Entry
from .forms import TopicForm, EntryForm

# Create your views here.

def index(request):
    """Домашняя страница приложения Learning Log."""
    return render(request, 'learning_logs/index.html')

def more_inf(request):
    return render(request,'learning_logs/more_inf.html')

class TopicsHome(ListView):
    model = Topic
    template_name = 'learning_logs/topics.html'
    context_object_name = 'topics'
    
    def get_queryset(self):
        public_topics = Topic.objects.filter(public=True).order_by('date_added')
        if self.request.user.is_authenticated:
            private_topics = Topic.objects.filter(owner=self.request.user).order_by('date_added')
            topics = public_topics | private_topics
        else:
            topics = public_topics
        return topics


class ShowTopic(LoginRequiredMixin, DetailView):
    model = Topic
    template_name = 'learning_logs/topic.html'
    context_object_name = 'topic'
    slug_url_kwarg = 'topic_slug'
  
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        topic = get_object_or_404(Topic, slug=self.kwargs['topic_slug'])
        check_topic_owner(topic.owner, self.request)
        context['entries'] = topic.entry_set.order_by('-date_added')
        return context


class AddTopic(LoginRequiredMixin, CreateView):  
    form_class = TopicForm
    template_name = 'learning_logs/new_topic.html'  

    def form_valid(self, form):
        new_topic = form.save(commit=False)
        new_topic.owner = self.request.user
        new_topic.save()
        return redirect('learning_logs:topics')
    
class AddEntry(LoginRequiredMixin, CreateView):
    form_class = EntryForm
    template_name = 'learning_logs/new_entry.html'
    slug_url_kwarg = 'topic_slug'

    def form_valid(self, form):
        topic = get_object_or_404(Topic, slug=self.kwargs['topic_slug'])
        check_topic_owner(topic.owner, self.request)
        new_entry = form.save(commit=False)
        new_entry.topic = topic
        new_entry.save()
        return redirect('learning_logs:topic', topic_slug=topic.slug)


class EditEntry(LoginRequiredMixin, UpdateView):
    model = Entry
    form_class = EntryForm
    template_name = 'learning_logs/edit_entry.html'
    context_object_name = 'topic'
    slug_url_kwarg = 'entry_slug'

    def form_valid(self, form):
        entry = get_object_or_404(Entry, slug=self.kwargs['entry_slug'])
        topic = entry.topic
        check_topic_owner(topic.owner, self.request)
        form.save()
        return redirect('learning_logs:topic', topic_slug=topic.slug)


def check_topic_owner(owner, request):
    if owner != request.user:
        raise Http404
Answer

Las vistas basadas en funciones (FBV) y las vistas basadas en clases (CBV) tienen su lugar en los proyectos de Django. Por lo general, se reduce a la preferencia del desarrollador. Personalmente, prefiero FBV porque hay menos abstracción. ¡Aunque tampoco hay nada de malo en seguir la ruta CBV!

Si desea leer más sobre FBV y por qué uno podría preferirlo, consulte esta serie de artículos: https://spookylukey.github.io/django-views-the-right-way/