using model-translation for custom field

162 views
Skip to first unread message

Sergey Aganezov

unread,
Nov 27, 2013, 12:06:58 AM11/27/13
to django-mode...@googlegroups.com
Hi,

looking for a new web-project and right now I'm looking for model-i18n tool. Django-model-translation looks very decent, but I'm a bit worried about some accpects.

So I got a question of sorts: will django-modeltranslation correctly work with custom field, that I inherit from 1) TextField 2) BleachField from django_bleach. Basicly, what should I be aware of, when I'm creating my custom field, inheriting like in either of those two cases? In other terms, what under-the-hood-twicks of dajngo-modeltranslation I should not interrapt, like what method not to override, etc.

If we clarify this here I'll be more than glad to update the docs in this regard, so everyone else, who'll get this question later, would find an answer in the docs.

Sincerely, Sergey Aganezov.

lasizoillo

unread,
Nov 27, 2013, 2:54:40 AM11/27/13
to django-mode...@googlegroups.com



2013/11/27 Sergey Aganezov <sergeyag...@gmail.com>

Hi,

looking for a new web-project and right now I'm looking for model-i18n tool. Django-model-translation looks very decent, but I'm a bit worried about some accpects.

So I got a question of sorts: will django-modeltranslation correctly work with custom field, that I inherit from 1) TextField 2) BleachField from django_bleach. Basicly, what should I be aware of, when I'm creating my custom field, inheriting like in either of those two cases? In other terms, what under-the-hood-twicks of dajngo-modeltranslation I should not interrapt, like what method not to override, etc.

Modeltranslation proxies translations fields to real ones. We are working with a HtmlField inherited from TextField without  mayor issues. 

Regards,

Javi
 

If we clarify this here I'll be more than glad to update the docs in this regard, so everyone else, who'll get this question later, would find an answer in the docs.

Sincerely, Sergey Aganezov.

--
Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "django-modeltranslation" sind.
Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von dieser Gruppe zu erhalten, senden Sie eine Email an django-modeltrans...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out

Sergey Aganezov

unread,
Nov 27, 2013, 9:11:49 AM11/27/13
to django-mode...@googlegroups.com
Hi Javi,

thank you for a quick response! 

You're saying that it maps, does it mean that it creates n copies of given field, keeping the field type and all it's methods, widgets, etc in place, and just creates getter, setter, manager patching magic? Also you said, that you are working with HtmlField inherited form TextField without major issues, so now I have to ask: how much customization have you added to you HtmlField (custom widget, custom methods, etc) and hom many of them a preserved without troubles? Also, what kind of non-major issues do you have working with custom field using modeltranslation? Can you specify a bit more details?

Sincerely, Sergey Aganezov.
Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von dieser Gruppe zu erhalten, senden Sie eine Email an django-modeltranslation+unsub...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out

lasizoillo

unread,
Nov 27, 2013, 9:44:20 AM11/27/13
to django-mode...@googlegroups.com



2013/11/27 Sergey Aganezov <sergeyag...@gmail.com>

Hi Javi,

thank you for a quick response! 

You're saying that it maps, does it mean that it creates n copies of given field, keeping the field type and all it's methods, widgets, etc in place, and just creates getter, setter, manager patching magic? 

In [1]: Notice._meta.fields
Out[1]: 
[<django.db.models.fields.AutoField: id>,
...
 <django.db.models.fields.CharField: title>,
 <modeltranslation.fields.TranslationField: title_es>,
 <modeltranslation.fields.TranslationField: title_pt>,
....
 <kernel.lib.ormutils.i18nAutoSlugField: slug>,
 <modeltranslation.fields.TranslationField: slug_es>,
 <modeltranslation.fields.TranslationField: slug_pt>,
...
 <kernel.lib.ormutils.HTMLField: text>,
 <modeltranslation.fields.TranslationField: text_es>,
 <modeltranslation.fields.TranslationField: text_pt>,
...
 <django.db.models.fields.related.ForeignKey: gallery>]

The field without lang suffix is a normal field preserving your not lang-related logic.

 
Also you said, that you are working with HtmlField inherited form TextField without major issues, so now I have to ask: how much customization have you added to you HtmlField (custom widget, custom methods, etc) and hom many of them a preserved without troubles?

Custom widget for wysiwyg editor, custom methods for clean and sanitize html, ... Test it, but probably you have not any trouble ;-)
 
Also, what kind of non-major issues do you have working with custom field using modeltranslation? Can you specify a bit more details?


We start with modeltranslations some versions ago. We had troubles, but now is very mature. Some of our problems are not related with custom fields:
- If you have a table with a lot of very large fields and you support a lot of languages you can get a limit for mysql row size. But other approach requires a lot of joins and more workload in db.
- Querys performed don't have (still) a method for ignore not active languages. Network is loaded with fields not used. I hope that this can be fixed (if is not fixed in lasts versions) with some free time to work in it.


Test it for you specific case, but most probably it will work fine.

Regards,

Javi

 
Sincerely, Sergey Aganezov.

On Wednesday, November 27, 2013 2:54:40 AM UTC-5, lasi zoillo wrote:



2013/11/27 Sergey Aganezov <sergeyag...@gmail.com>

Hi,

looking for a new web-project and right now I'm looking for model-i18n tool. Django-model-translation looks very decent, but I'm a bit worried about some accpects.

So I got a question of sorts: will django-modeltranslation correctly work with custom field, that I inherit from 1) TextField 2) BleachField from django_bleach. Basicly, what should I be aware of, when I'm creating my custom field, inheriting like in either of those two cases? In other terms, what under-the-hood-twicks of dajngo-modeltranslation I should not interrapt, like what method not to override, etc.

Modeltranslation proxies translations fields to real ones. We are working with a HtmlField inherited from TextField without  mayor issues. 

Regards,

Javi
 

If we clarify this here I'll be more than glad to update the docs in this regard, so everyone else, who'll get this question later, would find an answer in the docs.

Sincerely, Sergey Aganezov.

--
Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "django-modeltranslation" sind.
Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von dieser Gruppe zu erhalten, senden Sie eine Email an django-modeltranslation+unsub...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out

--
Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "django-modeltranslation" sind.
Reply all
Reply to author
Forward
0 new messages