How to convert Python Django Model object to dict with all of the fields intact?

To convert Python Django Model object to dict with all of the fields intact, we can use the queryset’s values().first method.

For instance, we write

type(o).objects.filter(pk=o.pk).values().first()

to create a queryset with

type(o).objects.filter(pk=o.pk)

then we get the values returned by the query set with values.

And then we return the first item returned by values with the first method.

first returns the item as a dictionary.