I have a model field for choosing multiple options. Here is the code for models and forms:
models.py:
CONDO_APARTMENT = 'Condo Apartment'
DETACHED_HOUSE = 'Detached House'
SEMI_DETACHED = 'Semi-detached'
TOWNHOUSE = 'Townhouse'
PROPERTY_TYPE = (
(CONDO_APARTMENT, 'Condo Apartment'),
(DETACHED_HOUSE, 'Detached House'),
(SEMI_DETACHED, 'Semi-detached'),
(TOWNHOUSE, 'Townhouse'),
)
property_type = 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)
Let's assume the selected choices were 'Condo Apartment' and 'Semi-detached'. The value stored on my database is this - ['Condo Apartment', 'Semi-detached']
Now this is in a list format, which makes sense, but it seems to have been converted to a string. When I try to call on property_type in a .html document...
{% for property in model.property_type %}
<p>{{ property }}</p>
{% endfor %}
The result is displayed in singular characters, like this:
[
'
C
o
n
d
o
a
p
.. and so on. Instead I want the result to be the values in the list, like this:
Condo apartment
Semi-detached
How do I do this? I tried experimenting with different model field types but CharField seems like the only appropriate one for MultipleChoiceField.