我一直在互联网上搜索一段时间,但无法找到解决该错误的方法。
我在stackoverflow上找到的最接近我的问题是:
Django 1.8 KeyError: 'manager' on relationship但在我看来,我正确地呼叫filter()
。 导致该错误的原因是什么?
以下是我如何调用该函数:
class DummySearchStrategy(GoalPartnersSearchStrategy):
def find(self, location, goal):
return Person.objects.filter(person_skill__skill__in = goal.relevantSkills, locationname = location)
PersonSkill有一个ForeignKey
个人(related_name='person_skill'
)和ForeignKey
个技能
这是追溯
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\rest_framework\views.py" in dispatch
466. response = self.handle_exception(exc)
File "C:\Python27\lib\site-packages\rest_framework\views.py" in dispatch
463. response = handler(request, *args, **kwargs)
File "C:\Users\kazimiera\PycharmProjects\coflow_site5\restserver\src\apps\prototype\views\dictionaries.py" in get
338. serializer = PersonGetSerializer(partners_generator.search(person, goal))
File "C:\Users\kazimiera\PycharmProjects\coflow_site5\restserver\src\apps\prototype\businesslogic\candidatelist\algorithms\partners_search.py" in search
19. self.how_to.find(localization, goal)
File "C:\Users\kazimiera\PycharmProjects\coflow_site5\restserver\src\apps\prototype\businesslogic\candidatelist\algorithms\partners_search.py" in find
12. return Person.objects.filter(person_skill__skill__in = goal.relevantSkills, locationname = location)
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in manager_method
127. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in filter
679. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
697. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_q
1310. clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in _add_q
1338. allow_joins=allow_joins, split_subq=split_subq,
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in build_filter
1156. value, lookups, used_joins = self.prepare_lookup_value(value, lookups, can_reuse, allow_joins)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in prepare_lookup_value
1003. value = value()
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py" in __call__
882. manager = getattr(self.model, kwargs.pop('manager'))
Exception Type: KeyError at /api/people/1/goals/1/candidates
Exception Value: u'manager'