django_find.models module

This module contains the Searchable mixin, the main public API of django-find.

class django_find.models.Searchable[source]

Bases: object

This class is a mixin for Django models that provides methods for searching the model using query strings and other tools.

classmethod by_fullnames(fullnames)[source]

Returns a unfiltered values_list() of all given field names.

classmethod by_json_raw(json_string, extra_model=None)[source]
classmethod by_query(query, aliases=None)[source]
classmethod by_query_raw(query, mode='SELECT', fullnames=None, extra_model=None)[source]

Returns a PaginatedRawQuerySet for the given query.

classmethod dom_from_query(query, aliases=None)[source]
classmethod get_aliases()[source]

Returns a list of the aliases, that is, the names of the fields that can be used in a query.

classmethod get_caption_from_selector(selector)[source]
classmethod get_class_from_fullname(fullname)[source]

Given a name in the format “Model.hostname”, this function returns a tuple, where the first element is the Model class, and the second is the field name “hostname”.

The Model class must inherit from Searchable to be found.

classmethod get_default_searchable()[source]
classmethod get_field_from_selector(selector)[source]

Given a django selector, e.g. device__metadata__name, this returns the class and the Django field of the model, as returned by Model._meta.get_field(). Example:

device__metadata__name -> (SeedDevice, SeeDevice.name)
classmethod get_field_handler_from_alias(alias)[source]

Given an alias, e.g. ‘host’, ‘name’, this function returns the handler.FieldHandler.

@type name: str @param name: e.g. ‘address’, or ‘name’

classmethod get_field_handler_from_field(field)[source]
classmethod get_field_handler_from_fullname(fullname)[source]

Given a fullname, e.g. ‘Device.host’, ‘Author.name’, this function returns the handler.FieldHandler.

@type name: str @param name: e.g. ‘address’, or ‘name’

classmethod get_fullnames()[source]

Like get_aliases(), but returns the aliases prefixed by the class name.

classmethod get_object_vector_for(search_cls_list)[source]
classmethod get_object_vector_to(search_cls)[source]
classmethod get_primary_class_from_fullnames(fullnames)[source]
classmethod get_searchable()[source]
classmethod get_selector_from_alias(alias)[source]

Given alias (not a fullname), this function returns the selector in the following form:

component__device__host

@type name: str @param name: e.g. ‘address’, or ‘name’

classmethod get_selector_from_fullname(fullname)[source]

Given a name in the form ‘Unit.hostname’, this function returns a Django selector that can be used for filtering. Example (assuming the models are Book and Author):

Book.get_selector_from_fullname('Author.birthdate')
# returns 'author__birthdate'

Example for the models Blog, Entry, Comment:

Blog.get_selector_from_fullname('Comment.author')
# returns 'entry__comment__author'

@type name: str @param name: The field to select for @rtype: str @return: The Django selector

classmethod q_from_query(query, aliases=None)[source]

Returns a Q-Object for the given query.

searchable = ()
searchable_labels = {}
classmethod sql_from_json(json_string, mode='SELECT', extra_model=None)[source]
classmethod sql_from_query(query, mode='SELECT', fullnames=None, extra_model=None)[source]

Returns an SQL statement for the given query.

classmethod table_headers()[source]