Reputation: 388
I'm trying to display this models' object where the user is as same as the detail view user. here is my views:
class ScientificInfoView(FormMixin, DetailView):
model = ScientificInfo
template_name = 'reg/scientific-info.html'
form_class = ScientificInfoForm
def get_success_url(self):
messages.success(self.request, 'Profile details updated.')
return reverse('scientific-info', kwargs={'pk': self.object.pk})
def get_context_date(self, **kwargs):
context = super(ScientificInfoView, self).get_context_data(**kwargs)
#THIS IS THE LINE THAT WONT WORK#
context['result'] = Results.objects.filter(user=self.object.user)
context['sample'] = 'sample text sample text'
#################################
context['form'] = ScientificInfoForm()
return context
def post(self, request, pk):
self.object = self.get_object()
form = ScientificInfoForm(request.POST, instance=get_object_or_404(ScientificInfo, id=pk))
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
def form_valid(self, form):
f = form.save(commit=False)
f.user = self.object.user
f.save()
return super(ScientificInfoView, self).form_valid(form)
everything works fine except the result and sample data. it shows nothing in the template. It cant even render a simple text!
this is the templates:
{% for r in result %}
{{r}}
{% endfor %}
{{ sample }}
Upvotes: 0
Views: 24
Reputation: 51665
This is just a typo, the name is get_context_data and not get_context_datE
.
Upvotes: 1