mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Use a simpler form for creating items
This commit is contained in:
@@ -97,7 +97,32 @@ class QuotaForm(I18nModelForm):
|
||||
]
|
||||
|
||||
|
||||
class ItemFormGeneral(I18nModelForm):
|
||||
class ItemCreateForm(I18nModelForm):
|
||||
has_variations = forms.BooleanField(label=_('The product should exist in multiple variations'),
|
||||
help_text=_('Select this option e.g. for t-shirts that come in multiple sizes. '
|
||||
'You can select the variations in the next step.'),
|
||||
required=False)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
instance = super().save(*args, **kwargs)
|
||||
if self.cleaned_data.get('has_variations'):
|
||||
ItemVariation.objects.create(
|
||||
item=instance, value=__('Standard')
|
||||
)
|
||||
return instance
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
localized_fields = '__all__'
|
||||
fields = [
|
||||
'name',
|
||||
'admission',
|
||||
'default_price',
|
||||
'tax_rate',
|
||||
]
|
||||
|
||||
|
||||
class ItemUpdateForm(I18nModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['category'].queryset = self.instance.event.categories.all()
|
||||
@@ -120,21 +145,6 @@ class ItemFormGeneral(I18nModelForm):
|
||||
]
|
||||
|
||||
|
||||
class ItemCreateForm(ItemFormGeneral):
|
||||
has_variations = forms.BooleanField(label=_('The product should exist in multiple variations'),
|
||||
help_text=_('Select this option e.g. for t-shirts that come in multiple sizes. '
|
||||
'You can select the variations in the next step.'),
|
||||
required=False)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
instance = super().save(*args, **kwargs)
|
||||
if self.cleaned_data.get('has_variations'):
|
||||
ItemVariation.objects.create(
|
||||
item=instance, value=__('Standard')
|
||||
)
|
||||
return instance
|
||||
|
||||
|
||||
class ItemVariationForm(I18nModelForm):
|
||||
class Meta:
|
||||
model = ItemVariation
|
||||
|
||||
Reference in New Issue
Block a user