[Django]-How to Set Multiple Fields in Django Db Record

6👍

I haven’t tested this myself, but you can probably pass a dict to the .update() function from the Queryset API: https://docs.djangoproject.com/en/2.0/ref/models/querysets/#update

Foo.objects.get(pk=1).update(**data)

0👍

Correction on @brandon answer.

Make sure to use .filter() method instead of .get()
since .get method returns matching object or raise DoesNotExist exception

Wrong : Foo.objects.get(pk=1).update(**data)

Correct : Foo.objects.filter(pk=1).update(**data)

Leave a comment