You can use setattr :
f = Foobar.objects.get(id=1) foo = 'somefield' bar = 'somevalue' setattr(f, foo, bar) # f.foo=bar f.save()
[ setattr ] is an analogue of getattr() . The arguments are an object, a string, and an arbitrary value. A string can name an existing attribute or a new attribute. The function assigns a value to the attribute if the object allows it.
source share