skip to navigation
skip to content

mongoengine-mls 1.1.0

MultiLingualField for MongoEngine

Simple extension for MongoEngine, which adds MultiLingualField (based on MultiLingualString). Some self-describing examples:

from locale import setlocale, LC_ALL
from mongoengine import Document, connect
from mongoengine_mls import MultiLingualField

class Country(Document):
    meta = {"indexes": ["name.language"]}
    name = MultiLingualField(required=True)

setlocale(LC_ALL, "en_US.UTF-8")
connect("test")

ru = Country(name={"en": "Russia", "ru": u"Россия"})
ru.save()

print(ru.name)  # => Russia
print(ru.name >> "ru")  # => Россия

ru2 = Country.objects.first()
ru2.name = [
    {"language": "en", "value": "Russian Federation"},
    {"language": "ru", "value": u"Российская Федерация"}
]
ru2.save()

print(ru2.name)  # => Russia Federation
print(type(ru2.name))  # => <class 'mls.MultiLingualString'>
 
File Type Py Version Uploaded on Size
mongoengine-mls-1.1.0.tar.gz (md5) Source 2015-04-17 3KB
mongoengine_mls-1.1.0-py2.py3-none-any.whl (md5) Python Wheel 2.7 2015-04-17 4KB