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

Should ISO_3166_1_ALPHA2_COUNTRY_CODES be in choices format instead of as a flat tuple? #499

Open
mlissner opened this issue Sep 26, 2023 · 0 comments

Comments

@mlissner
Copy link
Contributor

mlissner commented Sep 26, 2023

Hi and thanks for the great package. We are making a field to hold ISO 3316 country codes, and we were tempted to use ISO_3166_1_ALPHA2_COUNTRY_CODES because it looked super convenient. Unfortunately, though, it's just a list of the country codes and so it can't be used as a choices field.

I figured there'd be a workaround so that we could do:

country = models.CharField(length=2, choices=ISO_3166_1_ALPHA2_COUNTRY_CODES)

But I couldn't think of anything I really liked except for:

ISO_3166_CHOICES = {i: i for i in ISO_3166_1_ALPHA2_COUNTRY_CODES}

That didn't really thrill me, so I looked in Github, and was amused to see that literally nobody has used this variable in a public repo. Go figure.

I wonder if it'd be more useful to have it as a dictionary. That'd allow it to be used in choices. This would work nicely:

{
    "US": "United States",
    "GB": "United Kingdom of Great Britain",
    "UA": "Ukraine",
    ...
}

Any interest in this?

@mlissner mlissner changed the title Should ISO_3166_1_ALPHA2_COUNTRY_CODES be in choices format? Should ISO_3166_1_ALPHA2_COUNTRY_CODES be in choices format instead of as a flat tuple? Sep 26, 2023
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