-
i like how your docs cover python and django style for queries. https://collerek.github.io/ormar/queries/filter-and-sort/#django-style_5 Well done Is there a way to have django style model managers using ormar? Really happy to discover ormar. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What do you mean by django model managers? You have "manager" ( |
Beta Was this translation helpful? Give feedback.
-
The only way I found, to add custom functions to a 'Queryset'. You need to override class NoteQueryset(QuerySet):
async def get_or_404(self, *args: Any, **kwargs: Any) -> Optional['Note']:
try:
return await self.get(*args, **kwargs)
except ormar.NoMatch:
raise HTTPException(status_code=404, detail='Note not found')
class NoteModelMetaclass(ModelMetaclass):
@property
def objects(cls: Type["T"]) -> "QuerySet[T]": # type: ignore
_ = super().objects
return NoteQueryset(model_cls=cls)
class Note(Base, metaclass=NoteModelMetaclass): If you know the better way, pls share it |
Beta Was this translation helpful? Give feedback.
What do you mean by django model managers?
You have "manager" (
QuerySet
) underobjects
like in django.If you want to register a new one you can manually create a
QuerySet
and assign it to the class, or subclassQuerySet
and add your own methods.