[Django]-Set django model instance field like dictionary

1👍

You could use the inbuilt __dict__ for this, as

from .models import Credentials

current_cre = Credentials.object.get(user=request.user)
current_cre.__dict__['fb_name'] = "Name"
current_cre.__dict__['fb_pass'] = "****"
current_cre.save()

if user is a unique field, then you could try this also,

from .models import Credentials

my_dict = {"fb_name": "Name", "fb_pass": "****"}
current_cre = Credentials.object.filtert(user=request.user).update(**my_dict)
👤JPG

2👍

Try this

List_Fields = [(f.verbose_name, f.name) for f in Credentials._meta.get_fields()]

for field_name, value in List_Fields:
    current_cre[field_name]=request.POST[field_name]

Leave a comment