简体   繁体   中英

Django haystack related name search

so i have the following models:

class Article(models.Model, PublicationMixin):
    publication = models.ForeignKey('Publication', related_name="articles")
    ...

class Publication(models.Model, PublicationMixin):
    is_visible = models.BooleanField(default=False)
    is_approved = models.BooleanField(default=False)
    ....

in my search_indexes.py i have:

class PublicationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    id = indexes.CharField(model_attr='id', null=True)

I am trying to apply a filter that goes into my searchform and returns only the publications that have articles.

How can i achieve that using haystack and related names?? I am using elastic search as the backend.

Have you tried to reference the articles field in the index like this: http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#advanced-data-preparation and then use the SearchQuerySetApi to retrieve the values you want: http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html

:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM