#24858: Add support for get_foo_display() with ArrayField
----------------------------------+------------------------------------
Reporter: MounirMesselmeni | Owner: asser
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by asser):
I think the usage in the description is slightly wrong; if specifying
choices for an ArrayField the choices themselves should be lists:
{{{#!python
class Example(models.Model):
CHOICES = (
([1, 2], 'value1'),
([3, 4], 'value2'),
([5], 'value3'),
)
multi_choices_array = ArrayField(
base_field=models.IntegerField(),
choices=CHOICES,
)
}}}
To have an ArrayField that only accepts certain values on the base field,
the usage would probably be:
{{{#!python
class Example(models.Model):
CHOICES = (
(1, 'value1'),
(2, 'value2'),
(3, 'value3'),
)
multi_choices_array = ArrayField(
base_field=models.IntegerField(choices=CHOICES),
)
}}}
Then supposedly you could add a forms.MultipleChoiceField to fill in the
array's values?
Neither of the two forms above currently work. I've managed to modify the
postgres-specific code to handle the first case (choices being lists on
the ArrayField) based on chedi's patch -- see
https://github.com/asser/django/tree/ticket_24858 -- and am currently
trying to figure out what goes wrong in the validation handling of the
second case (choices on the base field).
--
Ticket URL: <https://code.djangoproject.com/ticket/24858#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.20223c064d98c282a314c13bc7d125cb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.