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

Automatically find model classes in modules #23

Closed
jayqi opened this issue Feb 14, 2021 · 1 comment · Fixed by #58
Closed

Automatically find model classes in modules #23

jayqi opened this issue Feb 14, 2021 · 1 comment · Fixed by #58
Labels
enhancement New feature or request

Comments

@jayqi
Copy link
Member

jayqi commented Feb 14, 2021

Would be a nice convenience feature if users could specify a module (or multiple modules) and have erdantic loop through its namespace and find any data model classes.

@jayqi jayqi added the enhancement New feature or request label Feb 14, 2021
@zamiramir
Copy link

Workarround for a module which contains classes of pydantic BaseModel:

import erdantic as erd
from pydantic import BaseModel
import some_module
import inspect

objs = set()
for name, obj in inspect.getmembers(some_module):
    if inspect.isclass(obj) and issubclass(obj, BaseModel):
        objs.add(obj)
        diagram = erd.create(obj)
        diagram.draw(f"diagram_{name}.svg")
diagram = erd.create(*objs)
diagram.draw("diagram_all.svg")

Keep up the good work! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants