这是我的模型:
class Picture(models.Model):
picture_id = models.IntegerField(db_column='PictureID', primary_key=True)
gold_item =models.ForeignKey(GoldItem,db_column="GoldItemID",related_name="pictures",on_delete=models.CASCADE)
gold_item_branch = models.ForeignKey(GoldItemBranch, db_column="GoldItemBranchID", related_name="pictures", on_delete=models.CASCADE)
code = models.CharField(db_column='Code', max_length=5, blank=True, null=True)
class GoldItemBranch(models.Model):
gold_item_branch_id = models.IntegerField(db_column='GoldItemBranchID', primary_key=True)
gold_item_id = models.IntegerField(db_column='GoldItemID')
gold_item_branch_name = models.CharField(db_column='GoldItemBranchName', max_length=30, blank=True, null=True)
我需要对上述模型中的多个列执行连接操作。列是 gold_item_id 和 gold_item_branch_id
我写了 SQL 查询:
select * from Pictures
join GoldItemBranches on Pictures.GoldItemID = GoldItemBranches.GoldItemID and Pictures.GoldItemBranchID = GoldItemBranches.GoldItemBranchID
我如何在 Django queryset 中执行相同的查询?
慕的地6264312
一只甜甜圈
喵喵时光机
相关分类