linuxlewis / djorm-ext-pgfulltext

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

Use the default SearchQuerySet class without overriding get_queryset #80

Open w0rp opened 8 years ago

w0rp commented 8 years ago

Overriding get_queryset causes problems when using YourManager.from_queryset(YourQuerySetClass) instead of return an instances of YourQuerySetClass, it will return an instance of SearchQuerySet. By changing the implementation of the SearchManager class, you can support this use case, by not overriding the get_queryset method so it will replace the BaseManager method, so it can then return the correct QuerySet subclass.

w0rp commented 8 years ago

I haven't tested this against all Django versions, but it should work on 1.8. I ran into this when I had a subclass of SearchQuerySet, a manager which was a sub class of SearchManager, and another sub class.

class MyBaseManager(SearchManager):
    pass

class MyQuerySet(SearchQuerySet):
    pass

class AnotherManager(MyBaseManager.from_queryset(MyQuerySet)):
   pass

With the code as it is now, the get_queryset method for AnotherManager will return just an instance of SearchQuerySet. With these changes here, it will return an instance of MyQuerySet.

w0rp commented 8 years ago

If the tests fail on older Django versions, it should be possible to detect the Django version and apply this patch differently by calling super() with the attribute set in versions which support the attribute, and falling back on the current implementation of the method.