2015-12-16 11 views
13

Dopo aver aggiornato il mio Django dalla versione 1.7 alla 1.9, il motore di ricerca, che è basato su Haystack e Solr, ha smesso di funzionare. Questo è ciò che ottengo:Haystack dice "Impossibile trovare il modello per SearchResult"

./manage.py shell 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
(InteractiveConsole) 
>>> from haystack.query import SearchQuerySet 
>>> sqs = SearchQuerySet().all() 
>>>sqs[0].pk 
u'1' 
>>> sqs[0].text 
u'\u06a9\u0627\u0645\u0631\u0627\u0646 \u0647\u0645\u062a\u200c\u067e\u0648\u0631 \u0648 \u0641\u0631\u0647\u0627\u062f \u0628\u0627\u062f\u067e\u0627\nKamran Hematpour & Farhad Badpa' 
>>> sqs[0].model_name 
u'artist' 
>>> sqs[0].id 
u'mediainfo.artist.1' 
>>> sqs[0].object 
Model could not be found for SearchResult '<SearchResult: mediainfo.artist (pk=u'1')>'. 

devo dire che il mio database non è empy e la mia configurazione è la seguente:

HAYSTACK_CONNECTIONS ={ 
    'default': { 
     'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 
     'URL': 'http://ahangsolr:8983/solr', 
    }, 
} 

E questa è la mia search_indexes.py:

import datetime 
from haystack import indexes 
from mediainfo.models import Album 
from mediainfo.models import Artist 
from mediainfo.models import PlayList 
from mediainfo.models import Track 
from mediainfo.models import Lyric 

class AlbumIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    artist = indexes.CharField(model_attr='artist', indexed=True) 
    publish_date = indexes.DateTimeField(model_attr='publish_date') 

    def get_model(self): 
     return Album 

    def index_queryset(self, using=None): 
     """Used when the entire index for model is updated.""" 
     return self.get_model().objects.filter(publish_date__lte=datetime.datetime.now()) 


class ArtistIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Artist 


class PlaylistIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return PlayList 


class TrackIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Track 


class LyricIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 

    def get_model(self): 
     return Lyric 
+0

Quale versione di Haystack stai usando? –

+0

@ThomasOrozco haystack 2.4.1 –

risposta

6

Sono stato in grado di risolvere il problema includendo un commit mancante alla versione 2.4.1. Il commit che risolto questo problema è stato https://github.com/django-haystack/django-haystack/commit/f1ed18313777005dd77ed724ecbfb27c0b03cad8

in modo da poter fare

pip install git+ssh://[email protected]/django-haystack/[email protected] 

per installare fino a quel specifico commesso.

+0

Grazie a @elchudi questa è stata la mia risposta, ma ho aggiunto alcune modifiche ad esso: pip install git + https: //[email protected]/django-haystack/[email protected] masterizza davvero lavoro –

+1

sei il benvenuto golden_boy615, non inseguirò @master in pip dato che il master cambierà tutto il tempo, e fino a una nuova versione di django-haystack è meglio tenere traccia di un commit specifico che conosci lavori – elchudi

1

E ' Sarebbe bene iniziare a controllare il registro dell'app per assicurarti che possa trovare il tuo modello (solo per essere sicuro).

from django.apps import apps as django_apps 
model = django_apps.get_model('mediainfo.artist') 
model.app_label, model.model_name 
assert model._meta.app_label == 'mediainfo' 
assert model._meta.model_name == 'artist' 

quindi vorrei controllare che cosa haystack sta tornando.

from haystack.utils.app_loading import haystack_get_model 
haystack_model = haystack_get_model('mediainfo', 'artist') 
haystack_model == model 

Se che non restituisce la stessa cosa (haystack_model = model!); allora dovrai scavare ulteriormente.

Tuttavia, il caricamento e la ricerca di modelli modificati tra 1.7.0 e 1.8.0 (deprecazione) e django.db.models.loading.get_model sono stati rimossi in 1.8.2. Dettagli su django-haystack #1206.

Pertanto, per django-haystack funzionare con 1.9.0 è necessario un rilascio che include this commit; vale a dire django-haystack>=2.4.0.

+1

la mia versione haystack è 2.4.1 e django_apps.get_model ('mediainfo.artist') restituisce con Nessun errore: . Qualcos'altro che posso fornire per ulteriori informazioni per aiutare a risolvere questo problema? –

+0

haystack_model == modello restituisce Vero ma c'è un errore qui quando si usa l'attributo app_label e nome_modello del modello: AttributeError: tipo oggetto 'Artista' non ha attributo 'nome_modello' e AttributeError: tipo oggetto 'Artista' non ha attributo 'app_label'! !! –

+1

di fronte a questo problema - hai ricevuto una correzione? per me haystack_model == modello e questo problema persiste –

Problemi correlati