djangodjango-managers

Django: how to test type of RelatedManager?


How to test the type of a RelatedManager in Django ?

assert type(qs) in [models.QuerySet, models.Manager]

fails if qs is a RelatedManager

how do I test if qs is a RelatedManager ?


Solution

  • ok, found a solution:

    assert isinstance(qs, (models.QuerySet, models.Manager))