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

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -