1

I am using django-modeltranslation for translation of my content.

If the value of a translated field is not set for a language then it automatically takes the value of the default language.

However, is there a way to know if value for a given language has been set?

If for example title_fr is not set, obj.title_fr will return the value of obj.title. How to know if the french version has been defined?

luc
  • 41,928
  • 25
  • 127
  • 172

1 Answers1

1

You can access original field value with instance.__dict__['title_fr'].

However, you probably want to customize fallback_values option:

https://django-modeltranslation.readthedocs.org/en/latest/usage.html#fallback-values

bmihelac
  • 6,233
  • 34
  • 45
  • 1
    The getattr(instance, 'title_fr') will also work! In fact, i had this problem because the translated field is a AutoSlugField (django_extensions) – luc Jan 22 '13 at 08:14
  • Thanks for the pointer on fallback-values but I am not sure it corresponds to this need. It seems that it can be used to get the default value of a translated field – luc Jan 22 '13 at 08:16
  • ``fallback_values = {'title': None}`` would make modeltranslation to return french title or None for ``title`` with french lang. This may be what you want. I did not try but think it should work. – bmihelac Jan 22 '13 at 08:24