Closed monospacedmagic closed 5 years ago
Hi
There is abstract=True
option for models meta, it's mentioned there https://tortoise-orm.readthedocs.io/en/latest/models.html
Is it what are you looking for?
Ohhh! Thanks, I somehow completely skipped that. It's exactly what I was looking for. :)
When using abstract=True
, it seems like the child classes don't inherit fields, ie:
class Entity(Model):
x = fields.IntField()
y = fields.IntField()
class Meta:
abstract = True
class ChestEntity(Entity, Model):
level = fields.IntField()
opened = fields.BooleanField()
Doesn't create an entity table but just leaves the chestentity table as id, level & opened.
Am I misunderstanding this feature?
Try just inheriting from Entity
instead of both Enitity
and Model
?
I realised we don't have a detailed example in the docs for this, nor is it part of the test suite... :disappointed:
Still doesn't seem to work.
@tcmal Can you please check with release v0.12.4 ? new docs: https://tortoise-orm.readthedocs.io/en/latest/models.html#inheritence
I want to add a
_d
attribute and a fewclassmethod
s and some regular methods to models by creating a subclass oftortoise.models.Model
that users of my framework can use. However, subclassingModel
would create a new database model, which is not what I want. From what I've seen, theModel
class contains a lot of logic, and it seems not feasible to create a new class withmetaclass=ModelMeta
. What are my options here? Am I missing something?