[Fixed]-Django convert model instance to dict

27👍

This actually already exists in Django, but its not widely documented.

from django.forms import model_to_dict
my_obj = User.objects.first()
model_to_dict(my_obj,
    fields = [...], # fields to include
    exclude =  [...], # fields to exclude
)

Leave a comment