Advertisement
vojd

django get_context_object

Oct 15th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. class SelectFeature(UpdateView):
  2.  
  3.     model = ApplicationFeature
  4.     form_class = FeatureSelectForm
  5.     template_name = 'form.html'
  6.  
  7.     def get_context_data(self, **kwargs):
  8.     # first fetch the context
  9.     context = super(SelectFeature, self).get_context_data(**kwargs*)
  10.     # fetch the object
  11.     obj = self.get_object()
  12.     # do some checking on the object
  13.         if obj.application.owner == self.request.user:
  14.         # the context object is a list of things which
  15.         # will be available in the template
  16.             context['object'] = obj
  17.     # return the context object which contains everything
  18.     return context
  19.  
  20.     def get_success_url(self):
  21.         return reverse('select_feature', kwargs={"pk":self.object.pk})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement