Skip to content

Query by active lang #39

@brahica

Description

@brahica

Hi,

Just asking, there is a ways filtring by active lang like :

from django.db import models
from localized_fields.fields import LocalizedCharField
from localized_fields.models import LocalizedModel
from django.utils.translation import activate

class MyModel(LocalizedModel, models.Model):
    name = LocalizedCharField(required=True)

"""
If MyModel instance are:
{
'name': {
        'en': foo,
        'es': bar
    }
}
"""

activate('en')    # Active lang 'en'
MyModel.objects.filter(name='foo')    # Find all instance that have name['en'] = 'foo'
MyModel.objects.filter(name__contains='foo')    # Find all instance that have name['en'] = '%foo%'

Thx ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions