Unable to use (...postgres.field) ArrayField with forms.SelectMultiple widget

Hi there, I try to use an ArrayField with a form, that has a field with SelectMultiple widget, but predefined values are not shown in browser.

Could anyone help me?

# models.py

class Box(models.Model):
   class Meta:
       ordering = ('name',)
   c = [x for x in range(1,15)]
   possible_item_counts = list(zip(c, c))
   name = models.CharField(max_length=50, verbose_name='Name'>)
   items = ArrayField(
       models.IntegerField(choices=possible_item_counts, blank=True),
       default = list,
       blank = True,
       size = 14,
       )
   def __str__(self):
       return f'{self.name} || {self.items}'
# forms.py

class BoxForm(forms.ModelForm):
  class Meta:
      model = Box
      fields = '__all__'
      widgets = {
          'name': forms.TextInput(
              attrs = {'class': 'form-control'}
              ),
          'items': forms.SelectMultiple(
              attrs = {'class': 'form-select'}
              ),
          }

<select></select> tag is rendered empty without any options…

no errors are given…

Side Note: When posting code here, enclose the code between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted. (I have taken the liberty of correcting your original post.
Please remember to do this in the future.)

<conjecture>
I’m not aware that Django provides any direct support for this.

I think you’ll need to primarily handle this yourself.

You’ll need to create a field for this and not just use a widget on the model field. To the form, the ArrayField is one field, commonly rendered as a comma-separated list of elements. It’ll be up to you to convert the list of elements stored in the ArrayField into the set of selected elements. Additionally, you’ll need to provide the list of choices to that field.
</conjecture>

Thank You!
your suggestion helped me to google differently, so I stumbled upon this code on: https://gist.github.com/danni/f55c4ce19598b2b345ef
works like charm on django 5.0.3

# customfields.py

from django import forms
from django.contrib.postgres.fields import ArrayField


class ChoiceArrayField(ArrayField):
    # Postgres ArrayField that supports the choices property.
    # Ref. https://gist.github.com/danni/f55c4ce19598b2b345ef.
    # credits: https://github.com/pcraciunoiu.

    def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.MultipleChoiceField,
            'choices': self.base_field.choices,
        }
        defaults.update(kwargs)
        return super(ArrayField, self).formfield(**defaults)

    def to_python(self, value):
        res = super().to_python(value)
        if isinstance(res, list):
            value = [self.base_field.to_python(val) for val in res]
        return value

    def validate(self, value, model_instance):
        if not self.editable:
            # Skip validation for non-editable fields.
            return

        if self.choices is not None and value not in self.empty_values:
            if set(value).issubset({option_key for option_key, _ in self.choices}):
                return
            raise exceptions.ValidationError(
                self.error_messages['invalid_choice'],
                code='invalid_choice',
                params={'value': value},
            )

        if value is None and not self.null:
            raise exceptions.ValidationError(self.error_messages['null'], code='null')

        if not self.blank and value in self.empty_values:
            raise exceptions.ValidationError(self.error_messages['blank'], code='blank')