I am a beginner in Django. And I need to convert Model instance in to dictionary similar as Model.objects.values do, with relation fields. So I write a little function to do thi
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 )