Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

context data wont display anything in detailview

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{% for r in result %}
    {{r}}
{% endfor %} 
{{ sample }}

>Solution :

This is just a typo, the name is get_context_data and not get_context_datE.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading