[Fixed]-Django: how to get field by field name from Model instance dynamically?

23👍

Use can use `getattr’. It works like this

field_name = "is_staff"
user = User.objects.get(pk=0)
field_name_val = getattr(user, field_name)

Leave a comment