Tuesday, July 31, 2012

Re: Adding more data to Generic Views

On Tue, Jul 31, 2012 at 11:15 PM, Karl Sutt <karl@sutt.ee> wrote:
So, in conclusion, Lachlan, you would want to do something like:

 def get_context_data(self,**kwargs):
        #Call the base implementation first to get a context
        context = super(PersonDetailView, self).get_context_data(**kwargs)
        #Add in a querysets
        context['job_list'] = Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['certificate_list'] = Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['claim_list'] = Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        return context

I have not tested this, but it gives you the idea. You'll want to filter the Vacancy, Certificate and Compensation objects by the person's ID. 

Great - thanks!

L, 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment