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

Noob question about accesing meta data #2638

Closed
ionesculiviucristian opened this issue Oct 24, 2022 · 2 comments
Closed

Noob question about accesing meta data #2638

ionesculiviucristian opened this issue Oct 24, 2022 · 2 comments

Comments

@ionesculiviucristian
Copy link

ionesculiviucristian commented Oct 24, 2022

Hi. I have the following class:

class Migration(BaseModel):
    name = CharField(null=True, unique=True)

    class Meta:
        table_name = "migrations"

How can I access the table name without using it like this:

Migration._meta.table.__name__

Need something more "public" kinda way.

@ionesculiviucristian
Copy link
Author

you can modify the source code just like me

Thanks for the response but I have no idea what you are referring to. What source code is that? Worst case I'm gonna add the same table_name on the parent class which is definitely not the way to do it.

@coleifer
Copy link
Owner

coleifer commented Oct 24, 2022

The table name is accessible via:

ModelClass._meta.table_name

The full list of available meta options is here: http://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata

The ._meta is a holdover from Django and is kinda a namespace for metadata of the model class itself. It can be considered part of the public interface.

Note: I've removed a couple comments that were unhelpful or missed the point.

Repository owner deleted a comment from James4Ever0 Oct 24, 2022
Repository owner deleted a comment from James4Ever0 Oct 24, 2022
Repository owner deleted a comment from James4Ever0 Oct 24, 2022
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

2 participants