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_query_raw
(query, mode='SELECT', fullnames=None, extra_model=None)[source]¶ Returns a PaginatedRawQuerySet for the given query.
-
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_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_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_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
(unique=False)[source]¶ Like get_aliases(), but returns the aliases prefixed by the class name.
-
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
-
searchable
= ()¶
-
searchable_labels
= {}¶
-
classmethod