November 2015
Beginner to intermediate
840 pages
26h 30m
English
PostGetMixin in Post ViewsInstead 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
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 ...
Read now
Unlock full access