I’m getting error Select a valid choice. LanguageChoice.EN is not one of the available choices.
for select input in my form.
I have registered Admin interface ArticleAdmin
for my model class Artcile
.
One of my attributes in Article
model is set to have the values selected from Enum.
How can I solve this ?
I guess I have to set some validation rules somewhere or move this choices out of Article
model but it seems I have not enough experience with Django to immediately feel where to go next .
Please see the code.
This classes I have in models.py
class LanguageChoice(Enum):
EN = "English"
DE = "German"
IT = "Italian"
class Article(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=50)
language = models.CharField(
max_length=2,
choices=[(tag, tag.value) for tag in LanguageChoice],
default=LanguageChoice.EN
)
Then in admin.py I have:
class ArticleAdmin(admin.ModelAdmin):
fields = ['title','author','language']
admin.site.register(Article, ArticleAdmin)