fixed form field generation

main^2
mtyton 2023-08-10 22:30:47 +02:00
rodzic d2fb27a2c3
commit 74e8822a18
3 zmienionych plików z 8 dodań i 19 usunięć

Wyświetl plik

@ -73,9 +73,14 @@ class ProductTemplateConfigForm(forms.Form):
def _create_dynamic_fields(self, template: ProductTemplate):
category_params = template.category.category_params.all()
for param in category_params:
queryset = ProductCategoryParamValue.objects.filter(param=param)
if queryset.count() >= 4:
widget = forms.Select(attrs={"class": "form-select"})
else:
widget = ButtonToggleSelect(attrs={"class": "btn-group btn-group-toggle"})
self.fields[param.key] = forms.ModelChoiceField(
queryset=ProductCategoryParamValue.objects.filter(param=param),
widget=ButtonToggleSelect(attrs={"class": "btn-group btn-group-toggle"}),
queryset=queryset,
widget=widget,
)
def __init__(

Wyświetl plik

@ -133,7 +133,7 @@ class ProductCategoryParamValue(ClusterableModel):
return
def __str__(self):
return f"{self.param.key}: {self.value}"
return str(self.value)
class ProductTemplate(ClusterableModel):

Wyświetl plik

@ -10,19 +10,3 @@
{% endfor %}
</div>
{% endwith %}
<!--
{% with id=widget.attrs.id %}
<div{% if id %} id="{{ id }}"{% endif %}
{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %}
>
{% for group, options, index in widget.optgroups %}
{% if group %}
<div><label>{{ group }}</label>{% endif %}{% for option in options %}<div>
{% include option.template_name with widget=option %}</div>{% endfor %}{% if group %}
</div>
{% endif %}
{% endfor %}
</div>
{% endwith %}
-->