| 1 | from typing import Any, List, Type |
| 2 | |
| 3 | from ninja import Schema |
| 4 | from ninja.orm.factory import create_schema |
| 5 | |
| 6 | __all__ = ["S", "L"] |
| 7 | |
| 8 | |
| 9 | # GOAL: |
| 10 | # from ninja.orm import S, L |
| 11 | # S(Job) -> JobSchema? Job? |
| 12 | # S(Job) -> should reuse already created schema |
| 13 | # S(Job, fields='xxx') -> new schema ? how to name Job1 , 2, 3 and so on ? |
| 14 | # L(Job) -> List[Job] |
| 15 | |
| 16 | |
| 17 | def S(model: Any, **kwargs: Any) -> Type[Schema]: |
| 18 | return create_schema(model, **kwargs) |
| 19 | |
| 20 | |
| 21 | def L(model: Any, **kwargs: Any) -> List[Any]: |
| 22 | schema = S(model, **kwargs) |
| 23 | return List[schema] # type: ignore |