sforkowany z mtyton/comfy
fixed form field generation
rodzic
d2fb27a2c3
commit
74e8822a18
|
@ -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__(
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
-->
|
||||
|
|
Ładowanie…
Reference in New Issue