我的错误栈如下:
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm\plugins\python\helpers\pycharm\django_manage.py", line 52, in <module>
run_command()
File "D:\Program Files\JetBrains\PyCharm\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\WebProjects/aisitev\manage.py", line 22, in <module>
main()
File "D:\WebProjects/aisitev\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\rebuild_index.py", line 65, in handle
call_command("update_index", **update_options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 181, in call_command
return command.execute(*args, **defaults)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 297, in handle
self.update_backend(label, using)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 342, in update_backend
max_pk = do_update(
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 119, in do_update
backend.update(index, current_qs, commit=commit)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 215, in update
prepped_data = self._prepare_object(index, obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 196, in _prepare_object
return index.full_prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 235, in full_prepare
self.prepared_data = self.prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 226, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 236, in prepare
return self.convert(super().prepare(obj))
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 105, in prepare
values = self.resolve_attributes_lookup(current_objects, attrs)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 157, in resolve_attributes_lookup
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'</module></module>
Is there anybody using Django taggit with haystack? How can we make tags field indexable by haystack?
I have tried:
class EventIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField( model_attr='descr_en', document=True, use_template=True)
text_tr = indexes.CharField(model_attr='descr_tr')
tags = indexes.MultiValueField()
def prepare_text(self, obj):
return '%s %s' % (obj.title_en, obj.descr_en)
def prepare_text_tr(self, obj):
return '%s %s' % (obj.title_tr, obj.descr_tr)
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
def get_model(self):
return Event
And i am using a custom searchqueryset for multilingual search :
class MlSearchQuerySet(SearchQuerySet):
def filter(self, **kwargs):
"""Narrows the search based on certain attributes and the default operator."""
if 'content' in kwargs:
kwd = kwargs.pop('content')
currentLngCode = str(get_language())
lngCode = settings.LANGUAGE_CODE
if currentLngCode == lngCode:
kwdkey = "text"
kwargs[kwdkey] = kwd
else:
kwdkey = "text_%s" % currentLngCode
kwargs[kwdkey] = kwd
if getattr(settings, 'HAYSTACK_DEFAULT_OPERATOR', DEFAULT_OPERATOR) == 'OR':
return self.filter_or(**kwargs)
else:
return self.filter_and(**kwargs)
Follow
asked May 17 ’13 at 16:19
1,1011313 silver badges3737 bronze badges
1 Answer
To get the tags into the search index we added them to our content template file eg
{{ object.title }}
{{ object.body }}
{% for tag in object.tags.all %} {{ tag.name }} {% endfor %}
{{ object.user.get_full_name }}
We also include it as a MultiValueField
tags = indexes.MultiValueField()
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
Haven’t had success trying to make boost work in either case, but the search definitely indexes them correctly.
Follow
answered May 17 ’13 at 17:03
59511 gold badge55 silver badges1010 bronze badges
Original: https://blog.csdn.net/weixin_42155685/article/details/122774550
Author: 北岭狼人
Title: django-haystack 对 多对多字段( ManyToManyField )进行索引
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/734088/
转载文章受原作者版权保护。转载请注明原作者出处!