在Django中设置学术或财务年度 [英] Setting Academic or Financial Years in Django
本文介绍了在Django中设置学术或财务年度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎微不足道,但是您如何在Django模型中设置财务年度或学年,例如2018/19或2017/2018,并参考当前财务年度进行查询,在这种情况下为2019/20
This may seem rather insignificant, but how do you set a financial or academic year, say 2018/19 or 2017/2018 in a Django model and reference the current financial year for querying, in this case 2019/20
推荐答案
考虑使用自定义查询集
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
这篇关于在Django中设置学术或财务年度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文