Closed ghulammasood closed 2 years ago
Hey There,
I have added two modelchoicefields on my model by following your blog. My Forms.py File Looks like this
Forms.py
from dynamic_forms import DynamicField, DynamicFormMixin
class WorkOrderForm(DynamicFormMixin, forms.ModelForm): def city_choices(form): to_cities = [] customer = form['customer'].value() contract_rates = ContractRates.objects.filter(customer=customer) for rate in contract_rates: to_cities.append(rate.city_to.id) return City.objects.filter(pk__in=to_cities)
customer = forms.ModelChoiceField(queryset=Customer.objects.all(), required=False) to_city = DynamicField(forms.ModelChoiceField, required=False, queryset=city_choices)
html_form: ... {% load widget_tweaks %} ...
Everything goes on smooth apart from the fact that the value for the selected customer is not fetched into the city_choices method. Let me know if you can see whats missing or where i could have gone wrong with it.
I was able to figure it out, I had not added the htmx to the base template.
Hey There,
I have added two modelchoicefields on my model by following your blog. My Forms.py File Looks like this
Forms.py
from dynamic_forms import DynamicField, DynamicFormMixin
class WorkOrderForm(DynamicFormMixin, forms.ModelForm): def city_choices(form): to_cities = [] customer = form['customer'].value() contract_rates = ContractRates.objects.filter(customer=customer) for rate in contract_rates: to_cities.append(rate.city_to.id) return City.objects.filter(pk__in=to_cities)
html_form: ... {% load widget_tweaks %} ...
Everything goes on smooth apart from the fact that the value for the selected customer is not fetched into the city_choices method. Let me know if you can see whats missing or where i could have gone wrong with it.