Monday, March 2, 2015

Traversing relationships based on lookup strings

Hi,

Is there a Django function that takes a model instance and a lookup string, and returns the value of the related field?

For example:

the_function_i_am_looking_for(trip, 'booking__client__name')

would return the same as:

trip.booking.client.name

Thanks,

Francis

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/FB0F25B1-00B0-4CD5-A62D-B9CE44F189C8%40devrx.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment