tortoise / tortoise/tortoise-orm
Model printing requires the output of the primary key value
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
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__}>"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Model class and compare its current str behavior with repr. Verify the requested output for models with and without a primary-key value, and consider whether existing model representation tests cover both cases; done means printing includes the model name and, when present, its primary key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100