| 19 | | example = Example.objects.create(multi_choices_array= [1, 2]) |
| 20 | | example.get_multi_choices_array_display() |
| 21 | | # Will raise a Type Error exception |
| | 19 | # Adding this method will show the values |
| | 20 | def multi_choices_array_display(self): |
| | 21 | result = '' |
| | 22 | choices = dict(self.CHOICES) |
| | 23 | for index, value in enumerate(self.multi_choices_array): |
| | 24 | result += "{0}".format(choices[value]) |
| | 25 | if not index == len(self.multi_choices_array) - 1: |
| | 26 | result += ', ' |
| | 27 | return result |
| | 28 | |
| | 29 | example = Example.objects.create(multi_choices_array= [1, 2]) |
| | 30 | example.get_multi_choices_array_display() |
| | 31 | # Will raise a Type Error exception |
| | 32 | example.multi_choices_array_display() |
| | 33 | # Will print 'value1, value2' |