Model Query Django

I'm trying to query fields from another model in Django . I'm able to fetch the user information using the following method

def student(self, *args, **kwargs):
        std_name = Attendance.objects.get(roll=self.roll)
        return std_name.name

Now I need to find the student's assigned teacher from a different table, I need to fetch it only using the student name which I got using student() as I don't have any variable in my current table to reference it to fetch that information from the new table.

def teacher(self, *args, **kwargs):
        teacher_name = staff.objects.get(student=self.student)
        return teacher_name.name


But the above method is not working properly and is not populating the fields in my admin.py page . Can someone help me in fixing this issue

Back to Top