def save(self):
        assert self.is_valid()

        version_kwargs = self.cleaned_data.copy()
        product = version_kwargs.pop("product")
        idprefix = version_kwargs.pop("idprefix")
        priority = version_kwargs.pop("priority")

        # ensure priority is an int, if not, store "None"
        try:
            int(priority)
        except ValueError:
            priority = None

        self.save_new_tags(product)

        case = model.Case.objects.create(
            product=product,
            user=self.user,
            idprefix=idprefix,
            priority=priority,
            )

        version_kwargs["case"] = case
        version_kwargs["user"] = self.user

        del version_kwargs["add_tags"]
        del version_kwargs["add_attachment"]

        suite = version_kwargs.pop("suite", None)
        if suite:
            order = model.SuiteCase.objects.filter(
                suite=suite,
                ).aggregate(Max("order"))["order__max"] or 0
            model.SuiteCase.objects.create(
                case=case,
                suite=suite,
                user=self.user,
                order=order + 1,
                )

        productversions = [version_kwargs.pop("productversion")]
        if version_kwargs.pop("and_later_versions"):
            productversions.extend(product.versions.filter(
                    order__gt=productversions[0].order))

        for productversion in productversions:
            this_version_kwargs = version_kwargs.copy()
            this_version_kwargs["productversion"] = productversion
            caseversion = model.CaseVersion.objects.create(
                **this_version_kwargs)
            steps_formset = StepFormSet(
                data=self.data, instance=caseversion)
            steps_formset.save(user=self.user)
            self.save_tags(caseversion)
            self.save_attachments(caseversion)

        return case
Create new case and all called-for versions.
dataset/ETHPy150Open mozilla/moztrap/moztrap/view/manage/cases/forms.py/AddCaseForm.save