Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error working with IntegerChoices models #128

Open
mavenium opened this issue Apr 22, 2022 · 0 comments
Open

Error working with IntegerChoices models #128

mavenium opened this issue Apr 22, 2022 · 0 comments

Comments

@mavenium
Copy link

mavenium commented Apr 22, 2022

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant