这似乎微不足道,但是您如何在Django模型中设置财务年度或学年,例如2018/19或2017/2018,并参考当前财务年度进行查询,在这种情况下为2019/20
答案 0 :(得分:0)
考虑使用自定义查询集
class CustomQuerySet(models.QuerySet):
def current_financial_year(self):
return self.filter(datefield__gte=current_finyear_start, datefield__lte=current_finyear_end)
然后从中选拔一个经理
CustomManager = models.Manager.from_queryset(CustomQueryset)
# Then in your model:
class MyModel(models.Model):
objects = CustomManager()
#use it like this:
MyModel.objects.current_financial_year().filter(...)
MyModel.objects.current_financial_year().get(...)
检查https://docs.djangoproject.com/en/dev/topics/db/managers/#creating-a-manager-with-queryset-methods