You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to save heron transactions to a database in json format. Thus it would be convenient if the various model classes had a to_dict or similarly-named method that returns a dict representation of a model object. Preferably the dict returned could be passed to Model.init to reconstitute the object.
The text was updated successfully, but these errors were encountered:
@declaresub thanks for the suggestion! You can always convert a python object into a dictionary by using vars(), so you could do that no problem. Because this is not always clear, I'm adding a to_dict() instance method for convenience in PR #11
Actually, you cannot always convert a python object into a dictionary using vars -- instances of a class created with a slots attribute, in particular. But the real problem with this implementation is that it doesn't fit the use case of serializing to JSON. A Transaction object has a merchant attribute of type Optional[Merchant]. This to_dict method will not convert the Merchant object to a dict.
I want to save heron transactions to a database in json format. Thus it would be convenient if the various model classes had a to_dict or similarly-named method that returns a dict representation of a model object. Preferably the dict returned could be passed to Model.init to reconstitute the object.
The text was updated successfully, but these errors were encountered: