Want to level up your DRF ORM Query skills? Our Django DRF ORM Query Fundamentals Course covers everything from basics to advanced queries.
🔥 Join the Udemy Course today and start learning!
📌 Click here to enroll now!
You are working for an e-commerce platform that sells both physical and digital products. The company wants to display only active products to customers. Your task is to retrieve these active products from the products
table.
Write a Django query to fetch all active products from the products
table. A product is considered active if is_active = TRUE
.
- Select the following columns:
- (All Fields)
- Only include products where
is_active = TRUE
. - Order the results by
created_at
in descending order (newest first).
Here’s an example of the products
table (The actual data can be found in init.sql
):
id | name | slug | description | price | is_digital | is_active | created_at |
---|---|---|---|---|---|---|---|
1 | Laptop | laptop | High-performance laptop | 1200.00 | FALSE | TRUE | 2024-03-20 10:30:00 |
2 | E-book | ebook-guide | Digital e-book | 10.99 | TRUE | FALSE | 2024-02-10 09:00:00 |
3 | Headphones | headphones | Noise-canceling | 199.99 | FALSE | TRUE | 2024-03-18 14:15:00 |
You can view the database ERD here:
Write a Django query to return only the active products.
- 📌 Read the Setup Instructions to get everything up and running.
- Implement your solution in
views.py
inside the provided ViewSet. - You do not need to manually add a URL—the system will automatically register the ViewSet.
- Open your browser and navigate to:
👉http://localhost:8000/docs
to test your query.
You only need to set up the docker containers and images once for all challenges tagged as Scenario A (see challenge name). Each scenario uses slightly different data, tailored to match the specific challenge requirements.