Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search with inherit model #84

Open
LennyLip opened this issue Sep 21, 2016 · 1 comment
Open

Search with inherit model #84

LennyLip opened this issue Sep 21, 2016 · 1 comment

Comments

@LennyLip
Copy link

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 LennyLip changed the title Search with enhirit model Search with inherit model Sep 21, 2016
@LennyLip
Copy link
Author

LennyLip commented Sep 21, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant