Opened 10 years ago

Last modified 5 years ago

#24858 closed New feature

get_foo_display with the ArrayField — at Version 2

Reported by: Mounir Owned by:
Component: contrib.postgres Version: dev
Severity: Normal Keywords:
Cc: chedi Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mounir)

I think using ArrayField as a many choices field would be awesome.
Passing choices to ArrayField works fine with MultipleChoiceField on the form.
But calling get_foo_display return a TypeError: unhashable type: 'list', maybe this method need to check if the field is an ArrayField it can return a string representation of the choices separated by comma.

class Example(models.Model):
    CHOICES = (
        (1, 'value1'),
        (2, 'value2'),
        (3, 'value3'),
    )

    multi_choices_array = ArrayField(
        base_field=models.IntegerField(),
        choices=CHOICES,
    )

    example = Example.objects.create(multi_choices_array= [1, 2])
    example.get_multi_choices_array_display()
    # Will raise a Type Error exception

Change History (2)

comment:1 by Tim Graham, 10 years ago

Could you please add a code snippet of the expected behavior?

comment:2 by Mounir, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top