[Django]-Use variables when saving objects in Django

3👍

Gabi’s answer is exactly what you want. You could use setattr instead though:

setattr(user, field_to_edit, strip_tags(value))

Which is (very very slightly!) more intuitive.

0👍

You can use the getattr function:

getattr(user, field_to_edit) = strip_tags(value)

Leave a comment