17.2.2 Generic Behavior

If you examine the code in TagDetail and StartupDetail, you’ll notice that the get() method is similar. In fact, if our code were less specific and relied on more instance variables, then the get() method of both classes would be identical, as shown in Example 17.5.

Example 17.5: Project Code

organizer/views.py in 6b9ce75f10

 95     def get(self, request, slug):  96         obj = get_object_or_404(  97             self.model, slug--iexact=slug)  98         return render(  99             request, 100             self.template_name, 101             {self.context_object_name: obj})

To allow for our classes to both have the method defined in Example 17.5, the declarations of our class and attributes ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.