Skip to content

Commit f94e183

Browse files
committed
fix: 이번주 인기 문제
1 parent 445410b commit f94e183

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

  • backend/problem/views

backend/problem/views/oj.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,24 @@ def get(self, request):
5050
problems = Problem.objects.filter(
5151
contest_id__isnull=True,
5252
visible=True,
53-
).order_by('-curr_week_info__accepted')[:3]
53+
).values("_id", "title", "difficulty", "field", "curr_week_info")
54+
55+
sorted_problems = sorted(
56+
problems,
57+
key=lambda p: p["curr_week_info"].get("accepted", 0),
58+
reverse=True,
59+
)[:3]
5460

5561
data = [
5662
{
57-
"_id": p._id,
58-
"title": p.title,
59-
"difficulty": p.difficulty,
60-
"field": p.field,
61-
"accepted": p.curr_week_info.get("accepted", 0),
62-
"submission": p.curr_week_info.get("submission", 0),
63+
"_id": p["_id"],
64+
"title": p["title"],
65+
"difficulty": p["difficulty"],
66+
"field": p["field"],
67+
"accepted": p["curr_week_info"].get("accepted", 0),
68+
"submission": p["curr_week_info"].get("submission", 0),
6369
}
64-
for p in problems
70+
for p in sorted_problems
6571
]
6672
return self.success(data)
6773

0 commit comments

Comments
 (0)