class ModelAQuerySet(models.QuerySet["ModelA"]):
def custom_method(self) -> Self:
...
class ModelA(models.Model):
objects: ModelAQuerySet = ModelAQuerySet.as_manager() # Pyright: Manager cannot be assigned to queryset
Isn't it for all intensive purposes the closest to the most accurate type? While I understand Django is dynamically creating a new type, not typing this as the queryset will lose us all of the custom methods we added. I think django-types solves this problem for mypy with this plugin, but if you're using Pyright this is probably what you would want to do.
While I get this isn't technically accurate:
Isn't it for all intensive purposes the closest to the most accurate type? While I understand Django is dynamically creating a new type, not typing this as the queryset will lose us all of the custom methods we added. I think
django-types
solves this problem formypy
with this plugin, but if you're using Pyright this is probably what you would want to do.