django-multiselectfield icon indicating copy to clipboard operation
django-multiselectfield copied to clipboard

Error working with IntegerChoices models

Open mavenium opened this issue 3 years ago • 0 comments

Hello, thank you for creating this package. I created the MediaType model, which is made of IntegerChoices:


from django.db.models import IntegerChoices, TextChoices
class MediaType(IntegerChoices):
    PHOTO = 1, _('Photo')
    VIDEO_IGTV_REAL = 2, _('Video / IGTV / Reel')
    ALBUM = 8, _('Album')

Then I used it in the desired field in the ResourcePage model:


from extensions.choices import MediaType

from multiselectfield import MultiSelectField


class ResourcePage(models.Model):
    media_type = MultiSelectField(
        verbose_name=_('Media Type'),
        choices=MediaType.choices,
        min_choices=1
    )

Finally, my tests encounter the following error:


  File "/home/***/PycharmProjects/PhinixAutomation/.venv/lib/python3.8/site-packages/multiselectfield/db/fields.py", line 145, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/***/PycharmProjects/PhinixAutomation/.venv/lib/python3.8/site-packages/multiselectfield/db/fields.py", line 141, in get_prep_value
    return '' if value is None else ",".join(map(str, value))
TypeError: 'MediaType' object is not iterable


mavenium avatar Apr 22 '22 18:04 mavenium