Reputation: 47
I'm attempting to create a function to allow updates to fields based on the front-end input.
The handler would receive a profile_updates
dictionary with two keys. Each will contain a list of key/value pairs.
list_of_updates['custom_permissions'] = [{"is_staff":"True"},{"other_permission":"False"}]
def update_profile(message):
list_of_updates = message['profile_updates']
user_update_id = message['user_id']
for update in list_of_updates['custom_permissions']:
for key, value in update.iteritems():
User.objects.filter(id=user_update_id).update(key=value)
I would like to make 'key' a variable fed from the .iteritems().
Appreciate anyone's input on how, or if, this is possible.
Upvotes: 0
Views: 743
Reputation: 4043
You don't need to loop through the dict. You can pass it as a kwarg expansion.
def update_profile(message):
list_of_updates = message['profile_updates']
user_update_id = message['user_id']
for update in list_of_updates['custom_permissions']:
User.objects.filter(id=user_update_id).update(**update)
Upvotes: 1