gpt4 book ai didi

如果字段存在,则Django过滤查询集

转载 作者:行者123 更新时间:2023-12-04 10:03:49 24 4
gpt4 key购买 nike

我想过滤我的查询集当且仅当 loan存在于我的模型中 ShgGroupLoanMarking .

class ShgGroupLoanMarking(models.Model):
shg = models.ForeignKey(Shg, null=True)
category = models.CharField(max_length=25, choices=GROUP_CATEGORY, default="shg_group")
msss = models.ForeignKey(Msss, null=True)
shgmember = models.ForeignKey(ShgMember, null=True)
loan = models.ForeignKey(Loan, null=True)
date_of_marking = models.DateField(null=True)
paid = models.CharField(max_length=100, null=True)
loan_amount = models.CharField(max_length=100, null=True)
service_charge = models.CharField(max_length=100, null=True)
description = models.CharField(max_length=100, null=True)
status = models.CharField(max_length=100, null=True)
print_status = models.BooleanField(default=False)
sent_to_bank_status = models.BooleanField(default=False)
receipt_number = models.IntegerField(default=0)

这该怎么做?

最佳答案

ShgGroupLoanMarking.objects.filter(loan__isnull=False)

或者
ShgGroupLoanMarking.objects.exclude(loan=None)

关于如果字段存在,则Django过滤查询集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28875726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com