我有一个数据库
Pattern
对象,我想得到所有有场的图案
Pattern.substring
包含在句子中:“这个句子必须包含所有返回的模式对象”。
例如,它返回
图案
用这些
.substring
价值观:
“这句话”、“全部”、“ce全部返回”。。。。
所以我需要像反向查找这样的东西。据我所知,
__search
应该这样做,但会引发错误:
Pattern.objects.filter(substring__search="This sentence has to contain all returned Pattern objects")
虽然我用
django.db.backends.postgresql
,它提出:
FieldError:不支持在字段上搜索CharField或join。
你知道怎么做吗?
完全回溯:
FieldError Traceback (most recent call last)
<ipython-input-16-80407f61e9e0> in <module>()
----> 1 Pattern.objects.filter(substring__search="This sentence has to contain all returned Pattern objects")
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/manager.py in manager_method(self, *args, **kwargs)
80 def create_method(name, method):
81 def manager_method(self, *args, **kwargs):
---> 82 return getattr(self.get_queryset(), name)(*args, **kwargs)
83 manager_method.__name__ = method.__name__
84 manager_method.__doc__ = method.__doc__
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/query.py in filter(self, *args, **kwargs)
834 set.
835 """
--> 836 return self._filter_or_exclude(False, *args, **kwargs)
837
838 def exclude(self, *args, **kwargs):
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/query.py in _filter_or_exclude(self, negate, *args, **kwargs)
852 clone.query.add_q(~Q(*args, **kwargs))
853 else:
--> 854 clone.query.add_q(Q(*args, **kwargs))
855 return clone
856
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/sql/query.py in add_q(self, q_object)
1251 # So, demotion is OK.
1252 existing_inner = {a for a in self.alias_map if self.alias_map[a].join_type == INNER}
-> 1253 clause, _ = self._add_q(q_object, self.used_aliases)
1254 if clause:
1255 self.where.add(clause, AND)
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/sql/query.py in _add_q(self, q_object, used_aliases, branch_negated, current_negated, allow_joins, split_subq)
1275 child, can_reuse=used_aliases, branch_negated=branch_negated,
1276 current_negated=current_negated, allow_joins=allow_joins,
-> 1277 split_subq=split_subq,
1278 )
1279 joinpromoter.add_votes(needed_inner)
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/sql/query.py in build_filter(self, filter_expr, branch_negated, current_negated, can_reuse, allow_joins, split_subq, reuse_with_filtered_relation)
1213 col = targets[0].get_col(alias, join_info.final_field)
1214
-> 1215 condition = self.build_lookup(lookups, col, value)
1216 lookup_type = condition.lookup_name
1217 clause.add(condition, AND)
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/sql/query.py in build_lookup(self, lookups, lhs, rhs)
1077 # A lookup wasn't found. Try to interpret the name as a transform
1078 # and do an Exact lookup against it.
-> 1079 lhs = self.try_transform(lhs, lookup_name)
1080 lookup_name = 'exact'
1081 lookup_class = lhs.get_lookup(lookup_name)
~/.virtualenvs/ticketscrawler/lib/python3.6/site-packages/django/db/models/sql/query.py in try_transform(self, lhs, name)
1113 "Unsupported lookup '%s' for %s or join on the field not "
1114 "permitted." %
-> 1115 (name, lhs.output_field.__class__.__name__))
1116
1117 def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
FieldError: Unsupported lookup 'search' for CharField or join on the field not permitted.