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
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/6O_nqDwvAAEJ.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
So, in conclusion, Lachlan, you would want to do something like:def get_context_data(self,**kwargs):context['job_list'] = Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
#Call the base implementation first to get a context
context = super(PersonDetailView, self).get_context_data(**kwargs)
#Add in a querysets
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 contextI 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.
On 31-7-2012 6:17, Lachlan Musicman wrote:So reverse relations.
> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
>
> def get_context_data(self,**kwargs):You don't need any of these. In your template, simply call:
> #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.all()
> context['certificate_list'] = Certificate.objects.all()
> context['claim_list'] = Compensation.objects.all()
{{ person.certificate_set.fieldname }}
If you insist on having them available as you do above, they should be:
context['job_list'] = self.get_object().vacancy_set.all()
context['certificate_list'] = self.get_object().certificate_set.all()
context['claim_list'] = self.get_object().compensation_set.all()
Required reading:
https://docs.djangoproject.com/en/1.4/ref/models/relations/
Also, skipping the tutorial is not recommended:
<https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system>
> Of course, the other thing that I can't help but thinking is that at this
> point, the non-generic-view method of urls/views might be a simpler way to
> go. While Generic Views are quite versatile, is there a point at which
> they are considered to restricting?
Not really. The only thing that bugs me about them is that adding extra
context requires sub-classing so you end up with a views.py that solely
consists of sub-classed generic views with 3 lines of get_context_data().
On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua <m.r.s...@gmail.com> wrote:
On 31-7-2012 6:17, Lachlan Musicman wrote:
> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
>
You don't need any of these. In your template, simply call:
{{ person.certificate_set.fieldname }}
I will try using person.vacancy_set.all now ...