You can get teacher and parents objects from student instance. student.teacher and student.teachers.all()
01.05.2012 11:46 пользователь "LJ" <ljayadams@gmail.com> написал:
-- 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))
--
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.
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