Im django noob here so I would like to get your support. Thank you so much in advanced.
1. My model.py:
class Province(models.Model):
province_name = models.CharField()
class Employee(models.Model):
first_name = models.CharField()
province = models.ForeignKey(Province, on_delete=models.CASCADE,)
2. My filters.py (django-filter)
from django_filters import FilterSet, filters
from .models import (
Employee,
Province,
)
class EmployeeFilter(FilterSet):
province_name_multi_select = (
filters.ModelMultipleChoiceFilter(
field_name="province_id",
queryset=Province.objects.values_list("id", "province_name"),
)
)
class Meta:
model = Employee
fields = [
"id",
"first_name",
"province",
]
3. My views.py
class EmployeeListView(FilterView):
model = Employee
queryset = Employee.objects.select_related(
"province",
)
form_class = EmployeeForm
strict = False
context_object_name = "employees_list"
filterset_class = EmployeeFilter
** 4. My employee_filter.html**
<select class="form-select" name="province_name_multi_select" id="multiple-select-field" multiple\>
{% for element in filter.form.province_name_multi_select %}
{{ element.tag }} \<= **Problem happened here**
{% endfor %}
</select\>
** 5. My problem** Above {{ element.tag }} produced <option value=“[1], ‘abc province’]” But what I want it to produce is, you can guess that <option value=“1” .
Once again, thank you.