deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.34k stars 257 forks source link

no fields appear for translation in admin panel #723

Closed Izaanaami closed 3 months ago

Izaanaami commented 3 months ago

hi. I installed modeltranslation package and everything said in the documentation but there is no new field added for translation in the admin panel. my project is up and has many models in the database, so when I run makemigration and migrate, it says there is no changes to apply. I'm using django 4.2 . here is my configuration:

settings.py :

INSTALLED_APPS = [
    'modeltranslation',
    ...
]

LANGUAGE_CODE = 'fa'

LANGUAGES = (
    ('fa', _('Farsi')),
    ('en', _('English')),
)

TIME_ZONE = 'Asia/Tehran'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = [
    BASE_DIR / 'locale/',
]

my model:

class Product(models.Model):
    name = models.CharField(max_length=200)
    ...

translation.py:

from modeltranslation.translator import register, TranslationOptions
from .models import Product

@register(Product)
class ProductTranslationOptions(TranslationOptions):
    fields: ('name',)
Izaanaami commented 3 months ago

ok it seems I'm just not that fluent in python. I declared fields in translation.py file using ' : ' instead of ' = ' :/

last-partizan commented 3 months ago

Yes, that's right!

I recommend using type-checker (like pyright, integrates very well with any editor supporting LSP), to catch those issues outright.