1👍
✅
Use annotate
and Count
.
Book.objects.annotate(n_libraries=Count('library')).filter(n_libraries__lt=3)
Source:stackexchange.com