python - Django Update Model Field with Variable User Input... .update(key=value) -


i'm attempting create function allow updates fields based on front-end input.

the handler receive profile_updates dictionary 2 keys. each contain 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']      update in list_of_updates['custom_permissions']:         key, value in update.iteritems():             user.objects.filter(id=user_update_id).update(key=value) 

i make 'key' variable fed .iteritems().

appreciate anyone's input on how, or if, possible.

you don't need loop through dict. can pass kwarg expansion.

def update_profile(message):     list_of_updates = message['profile_updates']     user_update_id = message['user_id']      update in list_of_updates['custom_permissions']:         user.objects.filter(id=user_update_id).update(**update) 

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -