question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I add functionality to all of my models without repeating myself?

See original GitHub issue

I want to add a _d attribute and a few classmethods and some regular methods to models by creating a subclass of tortoise.models.Model that users of my framework can use. However, subclassing Model would create a new database model, which is not what I want. From what I’ve seen, the Model class contains a lot of logic, and it seems not feasible to create a new class with metaclass=ModelMeta. What are my options here? Am I missing something?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, Jul 10, 2019

@tcmal Can you please check with release v0.12.4 ? new docs: https://tortoise-orm.readthedocs.io/en/latest/models.html#inheritence

0reactions
tcmalcommented, Jun 26, 2019

Still doesn’t seem to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keeping R code DRY with functions: Don't repeat yourself ...
Don't repeat yourself or the DRY principle is one of the best practices to writing good R. When you repeat the same block...
Read more >
Using Marshmallow without repeating myself - Stack Overflow
Marshmallow doesn't allow your parent model to have a schema, so I don't have information on custom validations there.
Read more >
Stop Repeating Yourself in Angular: How to Create Abstract ...
We have added some attributes and events shared by all text inputs, thus we will not have to add them again on our...
Read more >
Don't Repeat Yourself - DevIQ
The Don't Repeat Yourself (DRY) principle states that duplication in logic should be eliminated via abstraction; duplication in process should be eliminated ...
Read more >
~Don't~ Repeat Yourself - Hugging Face
Code for the attention mechanism is more or less copied over 50 times into different model files. Sometimes code of the whole BERT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found