goinnn/django-multiselectfield

Get Field Display Seems Not to work in template

abedyngash opened this issue ยท 4 comments

I'm trying to display each selected choice in the template with no success.
Here's my attempt:

REQUIRED_COMPLIANCES = (
		(1, 'Tax Compliance Certificate'),
		(2, 'H.E.L.B Compliance Certificate'),
		(3, 'D.C.I Clearance Certificate (Good Conduct)'),
		(4, 'C.R.B Clearance Certificate'),
	)

required_compliances = MultiSelectField(choices=REQUIRED_COMPLIANCES, max_choices=4, max_length=10)

In my template, {{vacancy.required_compliances}} returns:

Tax Compliance Certificate, H.E.L.B Compliance Certificate, D.C.I Clearance Certificate (Good Conduct), C.R.B Clearance Certificate

But what I'm trying to achieve is something like this:

Tax Compliance Certificate 
H.E.L.B Compliance Certificate
D.C.I Clearance Certificate (Good Conduct)
C.R.B Clearance Certificate

I've tried looping over the choices, but instead of the displays I'm getting the keys:

1
2
3
4

Any insights?

have you tried to use get_required_compliances_display in your loop?

Yes. I've tried the following:

{% for choice in get_required_compliances_display %}

- {{choice}}

{% endfor %}

But thay gives me

1
2
3
4

Instead of the displays

try:
{% for choice in get_required_compliances_list %}

  • {{choice}}

{% endfor %}

works 100%

otherwise: change the name of your field(delete the underscore : "requiredcompliances") ๐Ÿ˜

Works like charm! @goinnn May be this should be added somewhere in the documentation.