I want to update a table field by filtering the data and selecting a specific row, in below query "address1" is the field of User table which needs to be updated with value available in variable addr:
User.objects.filter(user_id=uid).update(address1=addr)
Above query works fine as I have given column name ="address1" in update option.
But my requirement is I want update field to be dynamic, i.e. it can be address1,address2, address3 (this is stored in a variable) Let's say it is stored in add_field variable then I can't use below as it will try to find add_field column in User table which is not present there:
User.objects.filter(user_id=uid).update(add_field=addr)
Query : How can I pass field name through variable/dynamically to update option in mentioned line of code or through any other option.
User.objects.filter(user_id=uid).update(**{add_field:addr})