Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion contentcuration/kolibri_public/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ def has_all_labels(self, field_name, labels):
annotations = {}
for bitmask_fieldname, bits in bits.items():
annotation_fieldname = "{}_{}".format(bitmask_fieldname, "masked")
filters[annotation_fieldname + "__gt"] = 0
# To get the correct result, i.e. an AND that all the labels are present,
# we need to check that the aggregated value is euqal to the bits.
# If we wanted an OR (which would check for any being present),
# we would have to use GREATER THAN 0 here.
filters[annotation_fieldname] = bits
# This ensures that the annotated value is the result of the AND operation
# so if all the values are present, the result will be the same as the bits
# but if any are missing, it will not be equal to the bits, but will only be
# 0 if none of the bits are present.
annotations[annotation_fieldname] = F(bitmask_fieldname).bitand(bits)

return self.annotate(**annotations).filter(**filters)
Expand Down