Sunday, May 09, 2021

Get Json of Django Object

I found unnecessarily difficult to get json from django model object. Here is my simple solution to get that done.
def get_json_object(obj, fields): return {f:obj.__dict__[f] for f in fields}

No comments:

AI

Despite the benefits of AI we are starving for humanity.