Open fabiocaccamo opened 8 years ago
I solved it by disabling fallback_languages in the translation options:
fallback_languages = {'default':()}
In any case I think that this should be the default behavior for BooleanFields.
I'll check this. You're right - False
value of BooleanField
shouldn't cause fallback.
But, why have you a BooleanField translated? Use django gettext function for it, it's easy.
I think the idea is to have a checkbox for every language, as in the example: published
.
@zlorf exactly :)
I don't understand you yet.
The goal is not to display translated True/False (which can be made with gettext
), but to have a set of boolean fields per language. Consider Article class: it has title, content and published flag (BooleanField). And developer want to have title and content translated, as well as separate checkbox for controlling publication of article for every language. So that he can publish article e.g. in English and German, but don't publish in Spanish yet, since the Spanish translation is missing.
Ah, now i understand! Thanks.
Just experienced the exact same thing; see for my original question: http://stackoverflow.com/questions/41998415/how-to-model-a-many-to-many-relation-when-the-target-model-is-a-tuple-in-django/ it explains why this is a nice feature...
from modeltranslation.utils import fallbacks
with fallbacks(False):
is_published = object.published
I just hit the same issue :( Going with fallbacks disabled for now...
MODELTRANSLATION_ENABLE_FALLBACKS = False
MODELTRANSLATION_ENABLE_FALLBACKS is a global option. so it can be not a good idea as only BooleanField has problem with fallback
It can be solved by overriding fallback_undefined:
class Product(models.Model):
published = models.BooleanField(...)
@register(Product)
class ProductTranslationOptions(TranslationOptions):
fields = ('published', )
fallback_undefined = {
"published": None,
}
Steps:
I think that BooleanField(s) should be excluded from the default fallback behavior.