Add comments
This commit is contained in:
parent
910322273e
commit
b55a8ffda6
|
|
@ -22,6 +22,7 @@ class RelatedObjectsCountMixin(models.QuerySet):
|
|||
"""QuerySet for ManyToMany related count filter"""
|
||||
|
||||
def get_related_objects_names(self):
|
||||
"""Get all related objects (with reversed)"""
|
||||
related_objects_names = []
|
||||
|
||||
for related_object in self.model._meta.related_objects:
|
||||
|
|
@ -31,7 +32,7 @@ class RelatedObjectsCountMixin(models.QuerySet):
|
|||
return related_objects_names
|
||||
|
||||
def annotate_related_objects_count(self):
|
||||
|
||||
"""Annotate all related objects to queryset"""
|
||||
annotations = {}
|
||||
for related_object in self.get_related_objects_names():
|
||||
annotations[f"{related_object}_count"] = models.Count(f"{related_object}")
|
||||
|
|
@ -39,6 +40,7 @@ class RelatedObjectsCountMixin(models.QuerySet):
|
|||
return self.annotate(**annotations)
|
||||
|
||||
def filter_related_gt(self, count):
|
||||
"""QuerySet filter by related objects count"""
|
||||
q_objects = Q()
|
||||
for related_object in self.get_related_objects_names():
|
||||
q_objects.add(Q(**{f"{related_object}_count__gt": count}), Q.OR)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user