Using prepare_FOO(self, object)
method, I'm trying to index a ForeignKey to get the name
attribute of my tags (travel, family, ...)
This is my model
class Blog(models.Model):
title = models.CharField(max_length=500)
description = models.TextField(blank=True, null=True)
tag = models.ForeignKey(Tag)
#...
And in my search_index.py, that's what I have:
class BlogIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
description = indexes.CharField(model_attr='description')
tag_name = indexes.CharField()
def get_model(self):
return Blog
def prepare_tag_name(self, obj):
return obj.tag.name
def index_queryset(self, using=None):
return self.get_model().objects.all().select_related('blog__tag')
... And my blog_text:
{{ object.title }}
{{ object.description }}
Any help would be appreciated, thank you!
get_model
returnsConvention
instead ofBlog
? – Thrown