linuxlewis/djorm-ext-pgfulltext

Search with inherit model

Opened this issue · 1 comments

Code:

ModelA(models.Model):
    text_for_search=models.CharField()
    objects = ModelAManager(
        fields=('text_for_search'),
        search_field='search_index',
        auto_update_search_field=True
    )

ModelB(ModelA)
    pass

ModelB.objects is QuerySet, not SearchQuerySet... How i can fix it?

ps. I don't wont to make ModelA abstract.

As workaround (for add searh() to query set):


class AddSearchQuerySet(models.QuerySet):
    def search(self, *args, **kwargs):
        return SearchQuerySet(model=ModelA, using=self._db).search(*args, **kwargs)

ModelB(ModelA)
    objects = models.Manager.from_queryset(AddSearchQuerySet)()

# this is for update parent search index, while saved child
models.signals.post_save.connect(auto_update_search_field_handler, sender=ModelB) 

update, seems it not very good workaround, because it changed self.model of qs.