I need some help with ManytoManyField
Here is simplified version of my models
class Person(models.Model):
name = models.CharField(maxlength=20)
class Company(models.Model):
class Department(models.Model):
persons = models.ManyToManyField(Person)
company = models.ForeignKey(Company)
So, the same person can be linked to multiple Departments.
A department is link to a company.
I want to display list of people link to Department AND department
Example:
Company Dept Person
------ ---- ----------
CompanyA HR Bob
CompanyA IT John
CompanyB IT Bob
My view looks like this (THIS IS WHERE I NEED HELP)
def company_detail(request, myid):
""" Main page to people per Company and Dept """
my_company = Company.objects.get(id=myid)
my_department = Department.objects.filter(company__id=myid)
my_persons = Module.objects.filter(site__department__id=myid)
return render_to_response('company_detail.html',
{'company': my_company, 'department_list': my_department,
'person_list': my_persons, })
In my Template I am unable to link person to Company -- think my VIEW
is not correct
Any comments will be appreciated.
Sorry for long post...
LIAM
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---