StaffCoder
Django
DjangoDjango 5.2Python 3.13
18 modules · 72 challengesSign up
Modules18 modules · 72 challenges
Let the database do the arithmetic: store-wide aggregates, per-row and grouped annotations, and F and Q expressions instead of Python loops.
Finish every challenge, or complete the star challenge, to complete the module.

Challenges

4 challenges

Store Totals Aggregate

Sign up to unlock
50%1 of 2 solvedmedium
About this challenge

The store metrics are built by pulling every order row into Python and adding the totals up in a loop. Replace that with one aggregate() call that returns revenue, average order value, order count and both extremes under defined names, with defined values for an empty store.

Read the full problem
Solved in a browser IDE and graded by tests. Sign up to solve

Per-Category Annotation

Sign up to unlock
100%1 of 1 solvedmedium
About this challenge

The category report builds its numbers with a COUNT and an AVG per category inside a Python loop. Annotate the category queryset instead, order it by an annotation, and group sales by month with values().

Read the full problem
Solved in a browser IDE and graded by tests. Sign up to solve

F And Q Expressions

Sign up to unlock
100%1 of 1 solvedmedium
About this challenge

Restocking reads a row into Python, adds to it and saves it back, so two deliveries recorded at once lose one of them, and the stock report compares every quantity against a number typed into the code. Move the arithmetic into the database with F expressions, compare a column against another column, and compose OR, AND and NOT into single filtered queries with Q objects.

Read the full problem
Solved in a browser IDE and graded by tests. Sign up to solve

Sales Analytics Report

STAR
Solving it completes the module
100%1 of 1 solvedmedium
About this challenge

The analytics page renders empty because three of its four sections were never written, and the one that works pulls every sale row into Python to add the amounts up in a loop. Build all four sections as ORM computations - a limited revenue ranking, a monthly grouping, an F-based margin feeding a Q-filtered flag set, and a store-wide aggregate block - each inside one query.

Read the full problem
Solved in a browser IDE and graded by tests. Sign up to solve

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.