Django models objects get attribute fields using string


We can get django objects fields using string by “getattr”. For instance, I have profile objects.

1
getattr(profile, "name")

Easy! 😀


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.