I am trying to create a multilingual text box in Django for my project. I use JSON to store translated text in a database and write my own code in a field to get it in the right language. For instance:
class MyModel(models.Model): text = MultilingualTextField(default_language="en") mymodel = MyModel.objects.create(text="Welcome") mymodel.text.val('fr','Bienvenue')
when the storage in the database becomes
{"en":"Welcome","fr":"Bienvenue","es":"Bienvenida"}
And we can call model.text.val('es') have "Bienvenida".
I use json dumps and json loads to store and retrieve the database value. My question is: is this a good way to do this? Does anyone have a better technique?
source share