def get_list(cls): response = [] now = datetime.datetime.now() next_year, next_month = Utils.nextmonth(year=now.year, month=now.month) for date in Lunchdate.objects.filter( date__month__in=[now.month, next_month]): queryset = Lunch.objects.filter(date=date.id).annotate( name=F('profile__name')).values('profile', 'name') profiles = Profile.objects.filter(user__active=True).exclude( id__in=[data.get('profile') for data in queryset]).values('id', 'name') response.extend(({ 'start': date.date, 'end': date.date, 'title': 'Eat', 'class': 'eat', 'content': str(queryset.count()), 'reason': queryset }, { 'start': date.date, 'end': date.date, 'title': 'No eat', 'class': 'no', 'content': str(profiles.count()), 'reason': profiles })) return response
def update_lunch(cls, profile): now = datetime.datetime.now() Lunch.objects.filter(profile_id=profile.id, date__date__gt=datetime.datetime.now()).delete() cls.create_lunch_days(year=now.year, month=now.month, lunch_users=[profile]) year, next_month = Utils.nextmonth(year=now.year, month=now.month) cls.create_lunch_days(year=year, month=next_month, lunch_users=[profile])
def lunch_creation(): current_month, current_year = Utils.get_current_date() year, next_month = Utils.nextmonth(year=current_year, month=current_month) LunchService.create_lunch_days(next_month, year, lunch_users=Profile.objects.filter(lunch=True))