I'm trying to update user in Django database.
Fetched data is as follows :
fetched_data = {
'id': 1,
'first_name': 'John',
'last_name': 'Doe',
'phone': '+32 12',
'mobile_phone': '+32 13',
'email': 'myemail@hotmail.com',
'username': 'myusername'
}
I get the user with this id as follows :
old_user = User.objects.get(pk=fetched_data['id'])
If I update the user as follows :
old_user.username = fetched_data['username']
old_user.first_name = fetched_data['first_name']
......
old_user.save()
it works fine, but I do not want to do it for every record, thus I tried something like :
for fetched_data_key in fetched_data:
old_user.fetched_data_key = fetched_data['fetched_data_key']
//old_user[fetched_data_key] = fetched_data['fetched_data_key'] --- I tried this way to
old_user.save()
But that doesn't work. Any idea how can I update the user without doing it for every record?