introduce docs -> models section mostly finished

This commit is contained in:
collerek
2020-08-12 16:24:45 +02:00
parent dd20fd9f01
commit 24eb0b30e7
23 changed files with 475 additions and 85 deletions

View File

@ -144,19 +144,21 @@ class QueryClause:
) -> Tuple[str, bool]:
has_escaped_character = False
if op in ["contains", "icontains"]:
if isinstance(value, orm.Model):
raise QueryDefinitionError(
"You cannot use contains and icontains with instance of the Model"
)
if op not in ["contains", "icontains"]:
return value, has_escaped_character
has_escaped_character = any(c for c in ESCAPE_CHARACTERS if c in value)
if isinstance(value, orm.Model):
raise QueryDefinitionError(
"You cannot use contains and icontains with instance of the Model"
)
if has_escaped_character:
# enable escape modifier
for char in ESCAPE_CHARACTERS:
value = value.replace(char, f"\\{char}")
value = f"%{value}%"
has_escaped_character = any(c for c in ESCAPE_CHARACTERS if c in value)
if has_escaped_character:
# enable escape modifier
for char in ESCAPE_CHARACTERS:
value = value.replace(char, f"\\{char}")
value = f"%{value}%"
return value, has_escaped_character

View File

@ -52,8 +52,7 @@ class Query:
if (
not self.model_cls.__model_fields__[key].nullable
and isinstance(
self.model_cls.__model_fields__[key],
orm.fields.foreign_key.ForeignKey,
self.model_cls.__model_fields__[key], orm.fields.ForeignKey,
)
and key not in self._select_related
):