Save django model with dictionaries

Save django model with dictionaries

Beware when queryset filter update() because it will pass model validation. Here is some example save model with dictionaries :

1
2
3
4
5
6
7
8
9
10
for k, v in account.items():
    setattr(instance, k, v)

try:
    instance.save()
except Exception, e:
    raise ValidationError(e)
else:
    updated += 1
    # print account

Leave a Reply

Your email address will not be published. Required fields are marked *