Code Room
Code reviewMedium
Question
Review this Python Django view.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
def order_summary(request): orders = Order.objects.filter(status="paid") rows = [] for order in orders: rows.append({ "id": order.id, "customer": order.customer.name, # FK lookup "items": order.lineitem_set.count(), # reverse FK "total": sum(li.price for li in order.lineitem_set.all()), }) return JsonResponse({"rows": rows})Run or narrate your approach, then ask the coach.