Hi guys I’m trying to create a form with a dropdown and other fields, I’m trying to get the data from the form but for some reason I’m not getting anything
This the template tha I’m using
{% extends "main_page_layout.dj.html" %}
{% block content %}
<form id="comunicate" method="post">{% csrf_token %}
<select name="company">
{% for company in companies %}
<option value={{company.id}}>{{ company.name }}</option>
{% endfor %}
</select>
<button id="comunicate" type="submit">Submit</button>
</form>
{% endblock %}
I’m using this piece of code to try to get the data from the form but it’s not working
This is the form that I’m using in django
class PruebaForm(forms.Form):
company = company = forms.ModelChoiceField(
queryset=CompanyInfo.objects.all(),
widget=forms.Select(attrs={"hx-get": "/load_users/", "hx-target": "#id_user"}),
)
user = forms.ModelChoiceField(
queryset=UserLicense.objects.all(),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['user'].queryset = UserLicense.objects.none()
if "company" in self.data:
company_id = self.data.get('company')
self.fields["user"].queryset = UserLicense.objects.filter(company_id=company_id)
If someone can explain why I’m not getting anything it would be helpful since I’m new with this, it works when i use {{form.as_p}} but the thing is that i have to it manually to
personalize the fields of the form