I’m having a problem using the application django-modeltranslation with a choice field.
My model Plan has a field called interval with the following choices:
class IntervalChoices(models.TextChoices):
DAY = DATE_INTERVALS.DAY, _("Day")
WEEK = DATE_INTERVALS.WEEK, _("Week")
MONTH = DATE_INTERVALS.MONTH, _("Month")
YEAR = DATE_INTERVALS.YEAR, _("Year")
class Plan(SoftDeleteBasedMixin):
INTERVALS = IntervalChoices
interval = models.CharField(
choices=INTERVALS.choices,
max_length=12,
default=INTERVALS.MONTH,
help_text="The frequency with which a subscription should be billed.",
)
I’m using django-modeltranslation to translate the label and the description of the plan on the admin by directly typing them on the Django Admin, but since those choices are preset I cannot edit them in the Admin.
I already used gettextlazy on the choices names and have the translations on the django.po
#:plan.py:44 msgid “Day” msgstr “Dia”
#:plan.py:45 msgid “Week” msgstr “Semana”
#:plan.py:46 msgid “Month” msgstr “Mês”
#:plan.py:47 msgid “Year” msgstr “Ano”
But when I change both the site or the admin to Portuguese, which is one of the languages I’m translating to the interval is shown in English.
This is my translation.py
from billing.models.plan import Plan
from modeltranslation.translator import TranslationOptions, register
@register(Plan)
class PlanTranslationOptions(TranslationOptions):
fields = ("label", "description")
Can someone help me to see how can I proceed with this?