I'm trying to get the count of the number of times a player played each week like this:
player.game_objects.extra(
select={'week': 'WEEK(`games_game`.`date`)'}
).aggregate(count=Count('week'))
But Django complains that
FieldError: Cannot resolve keyword 'week' into field. Choices are: <lists model fields>
I can do it in raw SQL like this
SELECT WEEK(date) as week, COUNT(WEEK(date)) as count FROM games_game
WHERE player_id = 3
GROUP BY week
Is there a good way to do this without executing raw SQL in Django?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…