0

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)

proof of ok values in DB

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

Luka Kunej
  • 35
  • 7
  • What does `SERVICE_AREAS` look like? What is returned when you access `some_model_instance_with_other_areas.other_areas` in the shell? – CoffeeBasedLifeform Jul 18 '18 at 10:25
  • My SERVICE_AREAS is created by a funciton 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've done a work around by adding this to my front end template to render the field: {{c.other_areas|dictsort:0}} – Luka Kunej Jul 19 '18 at 15:51

1 Answers1

0

There really isn't much source code here to go off of. But, it is clearly telling you that there is nothing there. You could not be passing the object to the front-end from your views which would make those template tags show None. Since you don't show what your model actually is, what data you are rendering from your views, nobody here can necessarily help you. I would recommend you post code so we can further understand how to help you.

Oh Great One
  • 374
  • 2
  • 17