Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert typesystem to JSON? #152

Open
TC-THREE opened this issue Mar 19, 2022 · 0 comments
Open

How to convert typesystem to JSON? #152

TC-THREE opened this issue Mar 19, 2022 · 0 comments

Comments

@TC-THREE
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant