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

ValueError when using lazystrings in model field choices #116

Open
simon-webisoft-com opened this issue Jul 27, 2023 · 0 comments
Open

ValueError when using lazystrings in model field choices #116

simon-webisoft-com opened this issue Jul 27, 2023 · 0 comments

Comments

@simon-webisoft-com
Copy link

from django.utils.translation import gettext_lazy as _
car_type = models.IntegerField(choices=((1, _('Sedan')), (2, _('Roadster'))), null=True, blank=True)

Raises exception: ValueError: Field 'car_type' expected a number but got 'S'. The 'S' comes from the label "Sedan".

The function FieldTypeGuesser.guess_format() is testing for non-string objects, if type(choice[1]) != str: and the type of this translatable string is: django.utils.functional.lazy.<locals>.__proxy__

My recommendation is test the value like so: if isinstance(choice[1], (tuple, list)):

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