def patch_list(self, request, **kwargs):
        """
        Since there is no RESTful way to do what we want to do, and since
        ``PATCH`` is poorly defined with regards to RESTfulness, we are
        overloading ``PATCH`` to take a single request that performs
        combinatorics and creates multiple objects.
        """
        import itertools
        from django.db import transaction
        from tastypie.utils import dict_strip_unicode_keys

        deserialized = self.deserialize(
            request,
            request.body,
            format=request.META.get('CONTENT_TYPE', 'application/json'))

        # verify input
        categories = deserialized.pop('categories', [])
        if not categories or not isinstance(categories, list):
            error_msg = "PATCH request must contain categories list."
            logger.error(error_msg)
            raise ImmediateHttpResponse(
                response=http.HttpBadRequest(error_msg))


        # do the combinatorics
        elem_lists = []
        for cat in categories:
            # do some type validation / variation
            if isinstance(cat, basestring):
                # simple case of create all the combinations
                cat = Category.objects.filter(id=self._id_from_uri(cat))
                elem_list = Element.objects.filter(category=cat)
            elif isinstance(cat, dict):
                # we must be working with at least one partial category
                category = Category.objects.filter(
                    id=self._id_from_uri(cat['category']))
                elem_list = Element.objects.filter(category=category)
                if 'exclude' in cat:
                    # exclude some element(s) from the combinations
                    exclude_uris = cat['exclude']
                    exclude_ids = [int(
                        self._id_from_uri(x)) for x in exclude_uris]
                    elem_list = [elem for elem in elem_list
                                 if elem.id not in exclude_ids]
                elif 'include' in cat:
                    # include only a few elements in the combinations
                    include_uris = cat['include']
                    include_ids = [int(
                        self._id_from_uri(x)) for x in include_uris]
                    elem_list = [elem for elem in elem_list
                                 if elem.id in include_ids]
                else:
                    # don't worry about this,
                    # it'll act like a list of categories
                    pass  # pragma: no cover
            else:
                error_msg = "categories list must contain resource uris or hashes."
                logger.error(error_msg)
                raise ImmediateHttpResponse(
                    response=http.HttpBadRequest(error_msg))

            # save off the elements from this category that will be used
            elem_lists.append(elem_list)

        # create all the combinations of elements from categories
        combinatorics = itertools.product(*elem_lists)

        # do the creation
        with transaction.commit_on_success():
            for combo in combinatorics:
                deserialized['elements'] = combo
                bundle = self.build_bundle(
                    data=dict_strip_unicode_keys(deserialized))
                bundle.request.META['REQUEST_METHOD'] = 'PATCH'
                if getattr(request, 'user', None):
                    bundle.request.user = request.user
                self.is_valid(bundle)
                self.obj_create(bundle, request=request)

        # don't try to reply with data, the request doesn't
        # really match the results.
        return http.HttpAccepted()
dataset/ETHPy150Open mozilla/moztrap/moztrap/model/environments/api.py/EnvironmentResource.patch_list/original