Skip to content

Instantly share code, notes, and snippets.

@amccloud
Created September 17, 2011 12:01
Show Gist options
  • Save amccloud/1223874 to your computer and use it in GitHub Desktop.
Save amccloud/1223874 to your computer and use it in GitHub Desktop.
class ProjectMixin(object):
project_url_pk = 'project_id'
project = None
def dispatch(self, request, *args, **kwargs):
self.project = get_object_or_404(Project, pk=kwargs.get(self.project_url_pk))
return super(ProjectMixin, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(ProjectMixin, self).get_context_data(**kwargs)
context.update({'project': self.project})
return context
class MilestonesView(ProjectMixin, generic.ListView):
model = models.Milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment