vitalik / django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
https://django-ninja.dev
MIT License
7.04k stars 423 forks source link

prefetch_related #557

Open hiaselhans opened 2 years ago

hiaselhans commented 2 years ago

When using nested models, i try to optimize queries by using prefetch_related and select_related beforehand. Using ModelSchema, we could inspect the model and schema and optimize queries in the ModelSchema metaclass.

ModelSchema would require attributes like:

class ModelSchema(Schema, metaclass=ModelSchemaMetaclass):
    _prefetch_related: List[Prefetch | str] | None
    _select_related: List[str] | None

Do you think such functionality could make it into django-ninja? If so, I'd be happy to invest some time...

ameyapathare commented 1 year ago

Did you end up implementing something like this?