orm icon indicating copy to clipboard operation
orm copied to clipboard

How to convert typesystem to JSON?

Open TC-THREE opened this issue 2 years ago • 0 comments

i need convert typesystem to json, but there is no way to find to_json

iused:

class BaseDatabase(orm.Model):
    fields = {}

    def __iter__(self):
        return self.__next__()

    def __next__(self):
        for k in self.fields.keys():
            if hasattr(self, k):
                yield (k, getattr(self, k))
class Json(js.JSONEncoder):

    def default(self, o):
        if isinstance(o, BaseDatabase):
            tmp = dict(o)
            if len(tmp.keys()) == 1 and "id" in tmp.keys():   # ForeignKey
                return tmp['id']
            return tmp
        return super().default(o)
class Mall(BaseDatabase)

TC-THREE avatar Mar 19 '22 11:03 TC-THREE