Models¶
Model Fields¶
Django key-value model field module.
- class confirm.django.db.models.fields.key_value.KeyValueField(*args, db_collation=None, **kwargs)¶
Django’s
TextField
on steroids and tuned for key-value based strings.When the value is fetched from the database, this field will return a
KeyValueDict
instance instead of the defaultstr
instance. This means you can easily iterate over the returned value.- from_db_value(value, *args, **kwargs)¶
Return
KeyValueDict
instance.- Parameters:
value (str) – The value
*args (list) – The args
**kwargs (dict) – The kwargs
- Returns:
The key value instance
- Return type:
confirm.utils.key_value.KeyValueDict
- pre_save(model_instance, add)¶
Ensure value is a
KeyValueDict
instance before model is saved.- Parameters:
model_instance (django.db.models.Model) – The model instance
add (bool) – Flag if model is added or updated
- Returns:
The value
- Return type:
confirm.utils.key_value.KeyValueDict
Model Managers¶
Django model manager for fulltext search.
- class confirm.django.db.models.manager.search.SearchManager(*args, **kwargs)¶
A model manager which supports MySQL and MariaDB full-text searches, by leveraging
confirm.django.db.models.query.SearchQuerySet
.- Parameters:
fields (None or list) – The search fields
- get_queryset()¶
Returns the search query set.
- Returns:
The search queryset
- Return type:
confirm.django.db.models.query.SearchQuerySet
Model Queries¶
Django model query set for fulltext search.
- class confirm.django.db.models.query.search.SearchQuerySet(fields=None, **kwargs)¶
A query set which supports MySQL and MariaDB full-text searches, with the fallback to a non-fulltext search.
- Parameters:
fields (None or list) – The search fields
**kwargs (dict) –
The keyword arguments
- fallback_search(search_term, fields=None)¶
Run a fallback search by using the
__icontains
filter.- Parameters:
search_term (str) – The search term
fields (None or list) – The search fields
- Returns:
The queryset
- Return type:
django.db.models.query.QuerySet
- fulltext_search(search_term, fields=None, mode=None)¶
Run a fulltext search with the
search_term
.The fulltext search will be run against the
fields
. If thefields
are not defined, thefields
argument of the instance will be used instead.By default the search mode will automatically be detected based on the received
search_term
. In case a boolean operator is found, the mode is automatically switched toBOOLEAN
, for everything else no specific mode is used.- Parameters:
search_term (str) – The search term
fields (None or list) – The search fields
mode (None or str) – The search mode
- Returns:
The MATCH AGAINST queryset
- Return type:
django.db.models.query.QuerySet
- search(search_term, fields=None, mode=None)¶
Run either a
fulltext search
or afallback search
, based on the configured database engine.- Parameters:
search_term (str) – The search term
fields (None or list) – The search fields
mode (None or str) – The search mode
- Returns:
The queryset
- Return type:
django.db.models.query.QuerySet