I am trying to setup some context variable for use in a template when
I execute a create view.
class ReviewTitleCreateView(CreateView):
model = Review
form_class = ReviewTitleCreateForm
template_name = 'papers/review_title.html'
def get_context_data(self, **kwargs):
context = super(ReviewTitleCreateView, self).get_context_data(**kwargs)
context['title'] = self.paper__title
print('Title: ',self.paper__title)
return context
def get(self, request, *args, **kwargs):
form = self.form_class(initial=self.initial)
return render(request, self.template_name, {'form': form})
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
# <process form cleaned data>
form.save()
return HttpResponseRedirect('#')
return render(request, self.template_name, {'form': form})
The 'Title: ' isn't even printed in the terminal nor is it available
in the template. Well, it is available I suppose (there is no error)
but empty.
The Review model:
class Review(models.Model):
"""
A review at a specific stage of one paper.
"""
INCLUDE_CHOICES = [(True,'Include'),(False,'Exclude')]
STAGES = [('Selection by Title','Selection by Title'),('Selection
by Abstract','Selection by Abstract'), ('Selection by Full
Text','Selection by Full Text')]
paper = models.ForeignKey(Paper, verbose_name=_('Paper'),
related_name="%(app_label)s_%(class)s_related", null=False,
blank=False, help_text=_("The reviewed paper."))
include = models.NullBooleanField("Choice",
choices=INCLUDE_CHOICES, default=True, null=False, blank=False,
help_text="Select Include or Exclude for this stage of review.")
exclusion_choice = models.ForeignKey(Exclusion, null=True,
blank=True, related_name="%(app_label)s_%(class)s_related")
exclusion_text = models.TextField(null=True, blank=True)
def __str__(self):
return self.paper.title
===================================
Thoughts?
--
MLHIM VIP Signup:
http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM
http://www.mlhim.org
Like Us on FB:
https://www.facebook.com/mlhim2
Circle us on G+:
http://goo.gl/44EV5
Google Scholar:
http://goo.gl/MMZ1o
LinkedIn Profile:
http://www.linkedin.com/in/timothywaynecook