def METHOD_NAME(self, field_name, labels):
    bitmasks = metadata_bitmasks[field_name]
    bits = {}
    for label in labels:
        if label in bitmasks:
            bitmask_fieldname = bitmasks[label]["bitmask_field_name"]
            if bitmask_fieldname not in bits:
                bits[bitmask_fieldname] = 0
            bits[bitmask_fieldname] += bitmasks[label]["bits"]
    filters = {}
    annotations = {}
    for bitmask_fieldname, bits in bits.items():
        annotation_fieldname = "{}_{}".format(bitmask_fieldname, "masked")
        # 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)