linuxlewis / djorm-ext-pgfulltext

PostgreSQL full-text search integration with django orm.
Other
250 stars 84 forks source link

Search with inherit model #84

Open LennyLip opened 8 years ago

LennyLip commented 8 years ago

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.

LennyLip commented 8 years ago

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.