簡體   English   中英

在peewee中加入3表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM