Code Room
Code reviewMedium
Question
Review this Python (Django ORM) view that serializes orders with their line items.
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_report(request): orders = Order.objects.filter( created__gte=last_month() ).order_by("-created") rows = [] for order in orders: rows.append({ "id": order.id, "customer": order.customer.name, "total": sum(item.qty * item.unit_price for item in order.items.all()), "warehouse": order.shipment.warehouse.code, }) return JsonResponse({"rows": rows})Run or narrate your approach, then ask the coach.