O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.6 Switching to GCBVs with PostGetMixin in Post Views

Instead of removing behavior from DateDetailView, we should be adding behavior to DetailView.

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.

Example 18.31: Project Code

blog/utils.py in a180f20424

 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required