18.6 Switching to GCBVs with
Instead of removing behavior from
DateDetailView, we should be adding behavior to
In Chapter 17, we saw that
DetailView uses the
get_object() method to actually fetch the object from the database. We can therefore create a mixin class to override the method and use multiple inheritance to override this in
DetailView and other GCBVs, as shown in Example 18.31.
1 from django.shortcuts import get_object_or_404 2 3 from .models import Post 4 5 6 class PostGetMixin: 7 8 def get_object(self, queryset=None): 9 year = self.kwargs.get('year') 10 month = self ...