LJ
unread,May 1, 2012, 1:46:02 AM5/1/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I have a Student model that stores information about a student,
including the student's teacher.
The teacher's information is stored in the Employee model that
inherits from the Person Model.
I am having trouble figuring out how to query the teacher, when a
student id is passed as an ajax argument to the view function.
I have no trouble returning the data about the parents and the
student, but my filter for querying the teacher info is incorrect.
Does anyone have any ideas how I can query for the teacher information
based on the models below?
#models.py
class Student(Person):
grade = models.ForeignKey('schools.Grade')
school = models.ManyToManyField('schools.School', blank=True,
null=True, related_name="school")
parents = models.ManyToManyField('parents.Parent', blank=True,
null=True)
teacher = models.ForeignKey(Employee, blank=True, null=True,
related_name='teacher')
class Employee(Person):
''' Employee model inherit Person Model'''
role=models.ForeignKey(EmployeeType, blank=True, null=True)
user=models.ForeignKey(User)
schools =
models.ManyToManyField(School,blank=True,null=True)
# views.py
def get_required_meeting_participants(request, template):
try:
id=request.GET['id']
except:
id=None
parents = Parent.objects.filter(student=id)
student = Student.objects.filter(pk=id)
teacher = Employee.objects.filter(pk=student.teacher_id) #this
line is incorrect...help, please?
data = {
'parents': parents,
'student': student,
'teacher': teacher,
}
return
render_to_response(template,data,
context_instance=RequestContext(request))