Source

django-related / related / views.py

Diff from to

related/views.py

     related_object_name = None
     cache_backend = cache
 
+    def dispatch(self, request, *args, **kwargs):
+        self.related_object = self.get_related_object()
+        return super(RelatedObjectMixin, self).dispatch(
+            request, *args, **kwargs
+        )
+
     def get_related_404_url(self):
         return self.related_404_redirect_url
 
     def get_context_data(self, *args, **kwargs):
         context = super(RelatedObjectMixin, self).get_context_data(*args, **kwargs)
 
-        related_object = self.get_related_object()
-
-        context['related_object'] = related_object
+        context['related_object'] = self.related_object
 
         related_object_name = self.get_related_object_name()
         if related_object_name:
-            context[related_object_name] = related_object
+            context[related_object_name] = self.related_object
 
         return context