Skip to content

Commit

Permalink
All backends: fixed more_like_this & deferreds
Browse files Browse the repository at this point in the history
Django removed the get_proxied_model helper function in the 1.3 dev
cycle:

https://code.djangoproject.com/ticket/17678

This change adds support for the simple new property access used by 1.3+

BACKWARD INCOMPATIBLE: Django 1.2 is no longer supported
  • Loading branch information
acdha committed Oct 30, 2012
1 parent 13e5a49 commit c8b601b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -43,7 +43,7 @@ Requirements
Haystack has a relatively easily-met set of requirements. Haystack has a relatively easily-met set of requirements.


* Python 2.5+ * Python 2.5+
* Django 1.2+ * Django 1.3+


Additionally, each backend has its own requirements. You should refer to Additionally, each backend has its own requirements. You should refer to
http://docs.haystacksearch.org/dev/installing_search_engines.html for more http://docs.haystacksearch.org/dev/installing_search_engines.html for more
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -109,7 +109,7 @@ Requirements
Haystack has a relatively easily-met set of requirements. Haystack has a relatively easily-met set of requirements.


* Python 2.5+ * Python 2.5+
* Django 1.2+ (may work on 1.1.2+) * Django 1.3+


Additionally, each backend has its own requirements. You should refer to Additionally, each backend has its own requirements. You should refer to
:doc:`installing_search_engines` for more details. :doc:`installing_search_engines` for more details.
Expand Down
14 changes: 4 additions & 10 deletions haystack/backends/elasticsearch_backend.py
Expand Up @@ -11,11 +11,7 @@
from haystack.models import SearchResult from haystack.models import SearchResult
from haystack.utils import get_identifier from haystack.utils import get_identifier
from haystack.utils import log as logging from haystack.utils import log as logging
try:
from django.db.models.sql.query import get_proxied_model
except ImportError:
# Likely on Django 1.0
get_proxied_model = None
try: try:
import requests import requests
except ImportError: except ImportError:
Expand Down Expand Up @@ -504,11 +500,9 @@ def more_like_this(self, model_instance, additional_query_string=None,
if not self.setup_complete: if not self.setup_complete:
self.setup() self.setup()


# Handle deferred models. # Deferred models will have a different class ("RealClass_Deferred_fieldname")
if get_proxied_model and hasattr(model_instance, '_deferred') and model_instance._deferred: # which won't be in our registry:
model_klass = get_proxied_model(model_instance._meta) model_klass = model_instance._meta.concrete_model
else:
model_klass = type(model_instance)


index = connections[self.connection_alias].get_unified_index().get_index(model_klass) index = connections[self.connection_alias].get_unified_index().get_index(model_klass)
field_name = index.get_content_field() field_name = index.get_content_field()
Expand Down
14 changes: 4 additions & 10 deletions haystack/backends/solr_backend.py
Expand Up @@ -9,11 +9,7 @@
from haystack.models import SearchResult from haystack.models import SearchResult
from haystack.utils import get_identifier from haystack.utils import get_identifier
from haystack.utils import log as logging from haystack.utils import log as logging
try:
from django.db.models.sql.query import get_proxied_model
except ImportError:
# Likely on Django 1.0
get_proxied_model = None
try: try:
from pysolr import Solr, SolrError from pysolr import Solr, SolrError
except ImportError: except ImportError:
Expand Down Expand Up @@ -264,11 +260,9 @@ def more_like_this(self, model_instance, additional_query_string=None,
limit_to_registered_models=None, result_class=None, **kwargs): limit_to_registered_models=None, result_class=None, **kwargs):
from haystack import connections from haystack import connections


# Handle deferred models. # Deferred models will have a different class ("RealClass_Deferred_fieldname")
if get_proxied_model and hasattr(model_instance, '_deferred') and model_instance._deferred: # which won't be in our registry:
model_klass = get_proxied_model(model_instance._meta) model_klass = model_instance._meta.concrete_model
else:
model_klass = type(model_instance)


index = connections[self.connection_alias].get_unified_index().get_index(model_klass) index = connections[self.connection_alias].get_unified_index().get_index(model_klass)
field_name = index.get_content_field() field_name = index.get_content_field()
Expand Down
14 changes: 4 additions & 10 deletions haystack/backends/whoosh_backend.py
Expand Up @@ -15,18 +15,14 @@
from haystack.models import SearchResult from haystack.models import SearchResult
from haystack.utils import get_identifier from haystack.utils import get_identifier
from haystack.utils import log as logging from haystack.utils import log as logging

try: try:
import json import json
except ImportError: except ImportError:
try: try:
import simplejson as json import simplejson as json
except ImportError: except ImportError:
from django.utils import simplejson as json from django.utils import simplejson as json
try:
from django.db.models.sql.query import get_proxied_model
except ImportError:
# Likely on Django 1.0
get_proxied_model = None


try: try:
import whoosh import whoosh
Expand Down Expand Up @@ -448,11 +444,9 @@ def more_like_this(self, model_instance, additional_query_string=None,
if not self.setup_complete: if not self.setup_complete:
self.setup() self.setup()


# Handle deferred models. # Deferred models will have a different class ("RealClass_Deferred_fieldname")
if get_proxied_model and hasattr(model_instance, '_deferred') and model_instance._deferred: # which won't be in our registry:
model_klass = get_proxied_model(model_instance._meta) model_klass = model_instance._meta.concrete_model
else:
model_klass = type(model_instance)


field_name = self.content_field_name field_name = self.content_field_name
narrow_queries = set() narrow_queries = set()
Expand Down

0 comments on commit c8b601b

Please sign in to comment.