def _update_spent(self):
today = date.today()
first_month_day = date(today.year, today.month, 1)
spent = Record.objects.filter(user=self.user,
transaction_type='EXP',
created_at__gte=first_month_day)
tags_list = []
for tag in self.get_tags_list():
tags_list.append(Q(tags=getattr(Record.tags, tag)))
if self.tags_type == 'INCL':
spent = spent.filter(reduce(OR, tags_list))
if self.tags_type == 'EXCL':
spent = spent.exclude(reduce(OR, tags_list))
spent = spent.aggregate(spent=Sum('amount'))
self.__spent = spent['spent'] if spent['spent'] else 0
评论列表
文章目录