Valid TextChoices for model but to be hidden in a Admin form

I’m using enumeration types, TextChoices to be precise, to enumerate possible and valid options for attribute in a model.
Later I use Django Admin to create new objects.

How can I show only subset of this enumerated options in a select input ?

For example, I have this code in model.py:

class LanguageChoice(models.TextChoices):
    EN = "EN", "English"
    DE = "DE", "German"
    IT = "IT", "Italian"

class Article(models.Model):
    title = models.CharField(max_length=100)
    language = models.CharField(
        max_length=2, choices=LanguageChoice.choices, default=LanguageChoice.EN
    )

Then in admin.py I have:

class ArticleAdmin(admin.ModelAdmin):
    fields = ['title','language']

admin.site.register(Article, ArticleAdmin)

Let’s say I want to achieve that user is able to choose (when creating new Article) only between EN and DE.
But option IT is still valid option to be saved in database.
How to achieve that ?

To do this on the admin, you’ll need a custom form. In that form you can define a form ChoiceField with a custom list of choices.

You can pull them from the enumeration type in two ways. One is to be explicit, building them up directily, and the other is to filter the existing choices:

In [11]: LanguageChoice.choices
Out[11]: [('EN', 'English'), ('DE', 'German'), ('IT', 'Italian')]

In [12]: [(LanguageChoice.EN.value, LanguageChoice.EN.label), (LanguageChoice.DE.value, LanguageChoice.DE.label)]
Out[12]: [('EN', 'English'), ('DE', 'German')]

In [13]: [c for c in LanguageChoice.choices if c[0] in ('EN', 'DE')]
Out[13]: [('EN', 'English'), ('DE', 'German')]

Hope that helps!