How to use Python type hints with Django QuerySet?

后端 未结 9 1034
一个人的身影
一个人的身影 2021-01-30 08:25

Is it possible to specify type of records in Django QuerySet with Python type hints? Something like QuerySet[SomeModel]?

For example, we have model:

9条回答
  •  情书的邮戳
    2021-01-30 08:44

    from typing import Iterable
    
    def func(queryset_or_list: Iterable[MyModel]): 
        pass
    

    Both of queryset and list of model instance is iterable object.

提交回复
热议问题