[英]Peewee foreign key from one table to different tabels
I'm working on simple asset manager database using peewee.我正在使用 peewee 开发简单的资产管理器数据库。 Each asset can belong to one of the types: image or video.
每个资产都可以属于以下类型之一:图像或视频。
Let's say it looks like this:假设它看起来像这样:
# MAIN ASSET
class Asset(Model):
name = CharField()
datetime = DateTimeField()
miniature = CharField()
preview = CharField()
type_ = ForeignKeyField()
class Meta:
database = DB
# TYPE SPECIFIC
class Image(Model):
resolution_x = IntegerField()
resolution_y = IntegerField()
channels = CharField()
layers = IntegerField()
class Meta:
database = DB
class Video(Model):
resolution_x = IntegerField()
resolution_y = IntegerField()
framerate = FloatField()
bitrate = FloatField()
duration = FloatField()
class Meta:
database = DB
I would like to keep all the assets in one table, asset specific fields in other and connect them with "type_" field (ex. using foreign key or something).我想将所有资产保存在一个表中,将资产特定字段保存在另一个表中,并将它们与“type_”字段连接起来(例如,使用外键或其他东西)。 How can I achieve that?
我怎样才能做到这一点? I suppose foreign key is a bad approach since it requires a predetermined model.
我认为外键是一种不好的方法,因为它需要预先确定的 model。
It looks like you are trying to create a Multiple Table Inheritance .看起来您正在尝试创建一个多表 Inheritance 。 Maybe this thread could be helpful
也许这个线程可能会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.