I've encountered the weirdest thing while developing a django-python web app.
I have a field in my database that I want to display on the frontend. The field is a MultiSelectField and the list is populated from a list
models.py
# Other service areas
other_areas = MultiSelectField(choices = SERVICE_AREAS, max_length=360,
default=None, null=True)
My SERVICE_AREAS is created by a function like this:
def get_service_areas():
#SERVICE_AREAS = [('None', '-------------')]
SERVICE_AREAS = []
sas = service_area.objects.all()
for s in sas:
SERVICE_AREAS.append((s.name, s.name))
return SERVICE_AREAS
I have a form from where I select the other "service areas" and everything is submitted to my database correctly (in pgadmin I see the correct values)
Then on the frontend side in my template i have this code to present the data:
index.html
<div class="email" style="padding-top: 10px;">{{c.service_area}}- {{c.service_area.said}} , Other SAID's: {{c.other_areas}}</div>
The weird part about this is that when the data actually show on my screen it turns up as the word "None" as many times is there are comma seperated values in that field. (If there are 3 service areas it will come up as None, None, None, if 4 service areas: None, None, None, None etc.) The rest of my data shows up correctly in the template. I'm kinda stumped and any ideas are welcome.
example output for the image I added above:
I have two values in the other_areas field (43006,43001) and it shows up like this