stephenmcd / mezzanine

CMS framework for Django
http://mezzanine.jupo.org
BSD 2-Clause "Simplified" License
4.74k stars 1.64k forks source link

Error adding translation for Injected Fields #1843

Open bookhankaa opened 6 years ago

bookhankaa commented 6 years ago

Following for this section of manual Translation for Injected Fields I'm trying to add translated extrafield for RichTextPage model: settings.py

EXTRA_MODEL_FIELDS = (
    (
        "mezzanine.pages.models.RichTextPage.quote",
        "TextField",
        ("Page's Quote",),
        {"blank": True},
    ),
)

translation.py

from modeltranslation.translator import translator
from mezzanine.pages.translation import TranslatedRichTextPage
from mezzanine.pages.models import RichTextPage

class TranslatedInjectedPage(TranslatedRichTextPage):
    fields = ('quote',),

translator.unregister(RichTextPage)
translator.register(RichTextPage, TranslatedInjectedPage)

and I get:

Error adding translation field. Model 'RichTextPage' already contains a field named 'content_en'.
bookhankaa commented 6 years ago
from modeltranslation.translator import translator, TranslationOptions
from mezzanine.pages.models import RichTextPage

class TranslatedInjectedPage(TranslationOptions):
    fields = ('quote',),

translator.unregister(RichTextPage)
translator.register(RichTextPage, TranslatedInjectedPage)

All fields and quote field transleted, content field NOT transleted.

bookhankaa commented 6 years ago

And just simple:

from modeltranslation.translator import translator
from mezzanine.pages.translation import TranslatedRichTextPage
from mezzanine.pages.models import RichTextPage

translator.unregister(RichTextPage)
translator.register(RichTextPage, TranslatedRichTextPage)

Doesn't works with error: Model 'RichTextPage' already contains a field named 'content_en'.

antnieszka commented 6 years ago

I have a similar problem - running version from master, commit aea2e994f429eedd2c304bd6895ee7e024c22ba0

abusquets commented 6 years ago

Me too

mfoacs commented 6 years ago

same here, 4.3.0 stable.

Kniyl commented 6 years ago

This is a bug of django-modeltranslation that never got addressed.

One workaround would be to manually add translated fields using EXTRA_MODEL_FIELDS for each target language.