pythondjangomezzaninedjango-modeltranslation

Django : Mezzanine front search module


I'm having a problem in my django's app using mezzanine.

I have specified models searchable this way :

SEARCH_MODEL_CHOICES = ('organization-pages.CustomPage',
                        'organization-network.DepartmentPage',
                        'organization-network.TeamPage',
                        'organization-network.Person',
                        'organization-projects.ProjectTopicPage',
                        'pages.Page',
                        'organization-media.Playlist',
                        'mezzanine_agenda.Event',
                        'organization-projects.Project',
                        'shop.Product',
                        'organization-magazine.Article')

PAGES_MODELS = ('organization-pages.CustomPage',
                'organization-magazine.Topic',
                'organization-network.DepartmentPage',
                'organization-network.TeamPage',
                'organization-projects.ProjectTopicPage',
                'shop.Product')

SEARCH_PARENTS_MODELS = ('organization-network.Person',)

And i haven't touched any of Mezzanine's source code.

I'm using django model-translation, having a object like that :

d = DepartementPage.objects.create()
d.title_fr = 'french'
d.title_en = 'english'

If i try to search it with Mezzanine's search engine, i'll only find it if i input the title of the language i'm currently using.

I mean if i'm using application in english, i'll not get my object searching 'french', while it should do

Do you know where my issue comes from ?


Solution

  • Using the model you have specified in your code above:

    d = DepartementPage.objects.create()
    d.title_fr = 'french'
    d.title_en = 'english'
    

    You should be able to successfully search the fields by using the following in your views.py:

    query = "search string"
    search_fields = ("title_fr", "title_en")
    results = DepartementPage.objects.search(query, search_fields=search_fields)
    

    From the docs:

    If search_fields is not provided in the call to search, the fields used will be the default fields specified for the model.

    You haven't posted the rest of your model fields, but I assume you also have the default title field (and title_fr, title_en are being generated automatically by the django-modeltranslation app). The title field is the default, and so will be the only field included in the search results. Good luck!