I would like to display all the student information like his ID, parent's first name,parent's first name, parent's email and the country in the django admin. These data are in the models and i would like to query and display them in django admin like a database table. The models for Student, StudentProfile, AdultProfile, StudentAdultRelationship is already set up. I am more interested in getting that data into the admin.
I have tried something this: from models import Student, StudentProfile,AdultProfile, StudentAdultRelationship def ChildParentRelationship(Student): queryset = Student.objects.all.order_by('name') for student in queryset: def StudentID(self): return student.pk def Parent_First_Name(self): try: adult = self.relationships.filter(role=StudentAdultRelationship.PARENT)[0].adult return '%s' % adult.profile.firstname except Exception: return '' Parent_First_Name.short_description = 'Parent First Name' def Parent_Last_Name(self): try: adult = self.relationships.filter(role=StudentAdultRelationship.PARENT)[0].adult return '%s' % adult.profile.firstname except Exception: return '' Parent_Last_Name.short_description = 'Parent Last Name' def Parent_Email: try: adult = self.relationships.filter(role=StudentAdultRelationship.PARENT)[0].adult return '%s' % adult.user.email except Exception: return '' Parent_Email.short_description = 'Parent-Email' def Parent_Country: try: adult = self.relationships.filter(role=StudentAdultRelationship.PARENT)[0].adult return '%s' % adult.profile.country except Exception: return '' Parent_Country.short_description = 'Parent-Country' admin.py from childparent import StudentID,Parent_First_Name,Parent_Last_Name,Parent_Email,Parent_Country class ChildParentAdmin(admin.ModelAdmin): list_display = ('displayname', 'StudentID','Parent_First_Name','Parent_Last_Name','Parent_Email','Parent_Country') search_fields = ['displayname',] Is there a better way in display queries in Django Admin? In need of some help. Would appreciate any help.... Thanks... -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/HqHQ4jCSdBkJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.