[英]Join 3 table in peewee
我希望能够在peewee中加入多个表。 这种情况对我来说很难弄清楚如何使其与peewee一起使用。 我有下表:用户,产品,图像
这是我的模型:
class user(BaseModel):
id = AutoField(primary_key=True)
username = CharField()
password = CharField()
class product(BaseModel):
id = AutoField(primary_key=True)
id_user = ForeignKeyField(user)
product_name = CharField()
product_price = IntegerField()
product_description = TextField()
class images(BaseModel):
id = AutoField(primary_key=True)
id_product = ForeignKeyField(barang)
image_name = TextField()
我想要类似product.id,user.username,product.product_name,product.price,product.product_description,images.image_name的输出
query = (Product
.select(Product, User, Image)
.join_from(Product, User)
.join_from(Product, Image))
for product in query:
print(product.product_name)
print(product.id_user.username)
print(product.images.image_name)
此处对此进行了非常详尽的记录: http : //docs.peewee-orm.com/en/latest/peewee/relationships.html
请阅读文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.