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

Model printing requires the output of the primary key value #1342

Open
Chise1 opened this issue Feb 16, 2023 · 6 comments
Open

Model printing requires the output of the primary key value #1342

Chise1 opened this issue Feb 16, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Chise1
Copy link

Chise1 commented Feb 16, 2023

Is your feature request related to a problem? Please describe.
When I print a model,I can only got model's name.
The str function should have the same logic as the repr function.
In the past, every time I printed a model, I had to print an extra pk field.
Describe alternatives you've considered
Rewrite the Model's function:str
like:

class Model(metaclass=ModelMeta):
    """
    Base class for all Tortoise ORM Models.
    """
    ...

    def __str__(self) -> str:
        if self.pk:
            return f"<{self.__class__.__name__}: {self.pk}>"
        return f"<{self.__class__.__name__}>"
@bekha-io
Copy link

That would be great! All other ORMs in comparison already have this feature.

@DenisFrunza
Copy link

Agree would be nice to see.

@long2ice
Copy link
Member

PR welcome

@DenisFrunza
Copy link

DenisFrunza commented Feb 18, 2023

I'll leave the PR here.

@Chise1 Chise1 mentioned this issue Feb 18, 2023
6 tasks
@long2ice
Copy link
Member

long2ice commented Mar 1, 2023

I notice that there is __repr__ has the behavior

@Chise1
Copy link
Author

Chise1 commented Mar 1, 2023

I thought repr should not affect str when refactored by the user, so I didn't call repr.

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

No branches or pull requests

4 participants