Last active
August 29, 2015 14:06
-
-
Save epicserve/eafce65f1426557e6a05 to your computer and use it in GitHub Desktop.
A handy little mixin for adding related objects to a view like DeleteView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.base import ContextMixin | |
from django.contrib.admin.utils import NestedObjects | |
class RelatedObjectsMixin(ContextMixin): | |
"""Adds the related_objects list to a views context """ | |
def get_context_data(self, **kwargs): | |
context = super(RelatedObjectsMixin, self).get_context_data(**kwargs) | |
collector = NestedObjects(using='default') | |
collector.collect([context['object']]) | |
to_delete = collector.nested() | |
context['related_objects'] = to_delete | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment