@cronjobs.register
def update_weekly_votes():
 recent = (datetime.now() - timedelta(days=7))
 q = QuestionVote.objects.filter(created__gte=recent)
 q = q.values_list('question_id', flat=True).order_by('question')
 q = q.distinct()
 q_with_recent_votes = list(q)
 q = Question.objects.filter(num_votes_past_week__gt=0)
 q = q.values_list('id', flat=True)
 q_with_nonzero_votes = list(q)
 qs_to_update = list(set((q_with_recent_votes + q_with_nonzero_votes)))
 for chunk in chunked(qs_to_update, 50):
  update_question_vote_chunk.apply_async(args=[chunk])

@ cronjobs . register def update_weekly_votes ( ) : recent = ( datetime . now ( ) - timedelta ( days = 7 ) ) q = QuestionVote . objects . filter ( created__gte = recent ) q = q . values_list ( 'question_id' , flat = True ) . order_by ( 'question' ) q = q . distinct ( ) q_with_recent_votes = list ( q ) q = Question . objects . filter ( num_votes_past_week__gt = 0 ) q = q . values_list ( 'id' , flat = True ) q_with_nonzero_votes = list ( q ) qs_to_update = list ( set ( ( q_with_recent_votes + q_with_nonzero_votes ) ) ) for chunk in chunked ( qs_to_update , 50 ) : update_question_vote_chunk . apply_async ( args = [ chunk ] )
keep the num_votes_past_week value accurate .