def __init__(self, *args, **kwargs):
        """Initialize form; restrict tag product choices."""
        super(EditTagForm, self).__init__(*args, **kwargs)

        # get all the cases this tag is applied to, if the cases belong to
        # a single product, this tag can be set to global or to that product.
        # if it's applied to cases from multiple products, then it must
        # remain global.
        products_tagged = model.Product.objects.filter(
            cases__versions__tags=self.instance).distinct()
        count = products_tagged.count()

        pf = self.fields["product"]
        self.initial["caseversions"] = list(
            self.instance.caseversions.values_list(
                "name", flat=True))

        if count > 1:
            # ro - no options
            # - no product set, cases applied from multiple products
            pf.queryset = model.Product.objects.none()
            pf.readonly = True
        elif count == 1:
            # rw - that product or none
            # - no product set, cases applied from single product
            # - product set, cases applied
            pf.queryset = products_tagged

        # else:
        # rw - all product options
        # - no product set, no cases applied
        # - product set, no cases applied
dataset/ETHPy150Open mozilla/moztrap/moztrap/view/manage/tags/forms.py/EditTagForm.__init__/original