17.1. Ninja About

17.1.1. Install

$ python -m pip install django-ninja

17.1.2. Assignments

# FIXME: Write tests

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: Django Ninja List
# - Difficulty: easy
# - Lines: 8
# - Minutes: 8

# %% English
# 0. Use `myproject.shop`
# 1. Create an endpoint `GET /api/v2/shop/products`
# 2. Endpoint should list all products in a database
# 3. Use package `ninja`

# %% Polish
# 0. Użyj `myproject.shop`
# 1. Stwórz endpoint `GET /api/v2/shop/products`
# 2. Endpoint ma wylistować wszystkie produkty w bazie danych
# 3. Użyj pakietu `ninja`

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
"""

# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()

...