def __init__(self, **kwargs): super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value,), invert=True) # Exclude current category from parents, because it cannot be its own child anyways filter_form_field_choices(self.fields["parent"], (kwargs["instance"].pk,), invert=True) self.fields["image"].widget = MediaChoiceWidget(clearable=True)
def __init__(self, request, **kwargs): self.request = request super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value,), invert=True) # Exclude current category from parents, because it cannot be its own child anyways filter_form_field_choices(self.fields["parent"], (kwargs["instance"].pk,), invert=True)
def __init__(self, request, **kwargs): self.request = request super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value,), invert=True) # Exclude current category from parents, because it cannot be its own child anyways category_queryset = Category.objects.filter(shops=get_shop(request)).exclude(status=CategoryStatus.DELETED) self.fields["parent"].queryset = category_queryset self.fields["parent"].choices = [(None, "----")] + [ (category.pk, category.name) for category in category_queryset.exclude(id=kwargs["instance"].pk) ]
def __init__(self, request, **kwargs): self.request = request super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value,), invert=True) # Exclude current category from parents, because it cannot be its own child anyways category_queryset = Category.objects.filter(shops=get_shop(request)).exclude(status=CategoryStatus.DELETED) self.fields["parent"].queryset = category_queryset self.fields["parent"].choices = [(None, "----")] + [ (category.pk, force_text(category)) for category in category_queryset.exclude(id=kwargs["instance"].pk) ]
def __init__(self, **kwargs): if not settings.SHUUP_ENABLE_MULTIPLE_SHOPS: initial = kwargs.get("initial", {}) initial["shops"] = [Shop.objects.first().pk] kwargs["initial"] = initial super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value,), invert=True) # Exclude current category from parents, because it cannot be its own child anyways filter_form_field_choices(self.fields["parent"], (kwargs["instance"].pk,), invert=True) if not settings.SHUUP_ENABLE_MULTIPLE_SHOPS: self.fields["shops"].disabled = True
def __init__(self, **kwargs): if not settings.SHUUP_ENABLE_MULTIPLE_SHOPS: initial = kwargs.get("initial", {}) initial["shops"] = [Shop.objects.first().pk] kwargs["initial"] = initial super(CategoryBaseForm, self).__init__(**kwargs) # Exclude `DELETED`. We don't want people to use that field to set a category as deleted. filter_form_field_choices(self.fields["status"], (CategoryStatus.DELETED.value, ), invert=True) # Exclude current category from parents, because it cannot be its own child anyways filter_form_field_choices(self.fields["parent"], (kwargs["instance"].pk, ), invert=True) if not settings.SHUUP_ENABLE_MULTIPLE_SHOPS: self.fields["shops"].disabled = True