I have 3 relational Django database tables and i want to display data in 'name_en' column in all the tables as labels, and 'id' in city table as value in Django MultipleChoiceField
| Example Table Structure |
Table 1 (province):
| id | name_en |name_ta |
| -------- | ---------- |---------- |
|1 | Western | - |
|2 | Central | - |
Table 2 (district):
| id | ForeignKey | Name_en |Name_ta |
| -------- | ----------- | ----------- |------- |
|1 | 2 | Kandy | - |
|2 | 1 | Colombo | - |
Table 3 (city):
| id | ForeignKey | Name_en |Name_ta |
| -------- | ----------- | ---------- |---------- |
|1 | 1 | Uduwela | - |
|2 | 2 | Homagama |- |
I want to display MultipleChoiceField in this format
<select>
<option value='1(city id)'>Western,Colombo,Homagama</option>
</select>
You could do something like this:
You loop over all the cities, get their district, and then get the district's province. Assuming a city can only have one district and a district can only have one province.