Code Room
Code reviewMediumcr-g065
Subject N plus one queriesLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development, Technology

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.

Talk through your review
Code to reviewpython
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.