Sunday, October 29, 2017

MultipleChoiceField is being displayed as a string instead of a list

I have a MultipleChoiceField forms field which shows up in the database like this. It seems to have been converted to a string in the database, because when I try to display it with a 'for property in property_type' statement in the HTML, it shows up like this. I want it to be displayed like this.  I have also tried using an ArrayField (shown below), but the result is the same.


models.py:

property_type = models.CharField(max_length=50, help_text="You can select more than 1 option")
property_type = ArrayField(models.CharField(max_length=50), help_text="You can select more than 1 option"))


forms.py:

property_type = forms.MultipleChoiceField(widget=forms.SelectMultiple, choices=BuyerListing.PROPERTY_TYPE)

HTML:

    {% for property in listing.property_type %}      <p>Property type: {{ property }}</p>      {% endfor %}


How do I get this MultipleChoiceField to load as a list so I can display it properly with a for statement?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cb625aff-b96e-4a07-9737-d89805085962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment