Skip to main content

MultiLingualField for MongoEngine

Project description

https://travis-ci.org/rembish/mongoengine-mls.svg?branch=master https://coveralls.io/repos/rembish/mongoengine-mls/badge.svg https://pypip.in/download/mongoengine-mls/badge.svg https://pypip.in/version/mongoengine-mls/badge.svg https://pypip.in/py_versions/mongoengine-mls/badge.svg https://pypip.in/implementation/mongoengine-mls/badge.svg https://pypip.in/status/mongoengine-mls/badge.svg https://pypip.in/wheel/mongoengine-mls/badge.svg https://pypip.in/egg/mongoengine-mls/badge.svg https://pypip.in/format/mongoengine-mls/badge.svg https://pypip.in/license/mongoengine-mls/badge.svg

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'>

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongoengine-mls-1.1.0.tar.gz (3.2 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page