I am using getattr to access properties of a model dynamically like so (Assuming the Student model has a property called name):
students = Student.objects.all()
property = 'name'
for student in students:
print getattr(student, property)
This works fine, however I'm wondering if it is possible to access a property of a related record in the same way, for example (Assuming each Student has a related Group with a property called title):
students = Student.objects.selected_related()
property = 'group.title'
for student in students:
print getattr(student, property)
With this, I just get the error 'Student has no attribute group.title'
Is there anyway to achieve this?
Any advice appreciated.
Thanks