0
我有一個模型在這裏如下:標註不返回預期的結果
class Project(models.Model):
project_id = models.CharField(max_length=10, blank=False, primary_key=True)
title = models.CharField(max_length=128, blank=False,)
start_date = models.DateField(null=False)
end_date = models.DateField(null=True)
total_amount = models.DecimalField(max_digits=10, decimal_places=2)
raised_amount = models.DecimalField(max_digits=10, decimal_places=2)
cause = models.ForeignKey('Cause', on_delete=models.SET('cause not set'))
ngo_id = models.ForeignKey('NGO', on_delete=models.SET('ngo not set'))
zip = models.IntegerField(blank = True)
reimagine_fees=models.DecimalField(max_digits=10, decimal_places=3,default=0.05)
person_of_contact = models.CharField(max_length = 100)
summary = models.TextField(blank = False)
story = models.TextField(blank = True)
fb_description=models.CharField(max_length = 301,blank=True)
tax_exemption_available = models.BooleanField(default=False)
banner = models.TextField(blank=True)
team_member_id = models.ForeignKey(Team_Member, on_delete=models.SET('team member not set'))
project_page_desc = models.CharField(max_length=300, blank=True)
def __str__(self):
return self.title
我試圖根據資金percetages篩選項目的對象,也就是raised_amount
和total_amount
的比例..我爲此使用註釋。但是,過濾器並沒有按照我預期的那樣給出結果。我的過濾器查詢是:
project_list = project_list.annotate(x=F('raised_amount')/F('total_amount')).exclude(x__gte=0.8)
project_list = project_list.annotate(x=F('raised_amount')/F('total_amount')).exclude(x__lte=0.2)
project_list = project_list.annotate(x=F('raised_amount')/F('total_amount')).exclude(x__lte=1, end_date__gte=datetime.date.today())
project_list
是所有Project
對象的查詢集。
幫助我在這裏...
你期待什麼? – e4c5
......這與你實際得到的有什麼不同? –
如果project_list是一個字典,你爲什麼要嘗試對它進行標註?你應該在QuerySet –