In django, we can update model instance field like:
from .models import Credentials
current_cre=Credentials.object.get(user=request.user)
current_cre.fb_name='Name'
current_cre.fb_pass='****'
current_cre.save()
Is there any way that I can do it like dictionary item:
current_cre['fb_name']='Name'
current_cre['fb_pass']='Pass'
So I can iterate the process like:
for field_name in List_Fields:
current_cre[field_name]=request.POST[field_name]
thanks in advance.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With