How to set django model field by name?

If you modify the value via setattr, you need to remember to save the model after modifying it. I’ve been bitten in the past where I changed the values but forgot to save the model, and got the same result.

setattr(f, 'bar', 'BAR')
f.save()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)