API Reference¶
Utility Functions¶
-
class
relatives.utils.
GenericObjects
(_object)¶ Search GenericForeignKey over all models and returns related objects if has relations with given object.
-
class
relatives.utils.
RelatedObject
(field, ct_pk)¶ Generates fake django RelatedObject
-
relatives.utils.
get_admin_url
(obj)¶ Return admin URL for given object (raise NoReverseMatch on error)
-
relatives.utils.
object_edit_link
(edit_text=None, blank_text=None)¶ Return function that takes an object and returns admin link to object
Arguments:
edit_text
is displayed in link textblank_text
is displayed in unlinked text (when no admin link)
edit_text
defaults to the object’s unicode representation andblank_text
defaults to the object’s unicode representation ifedit_text
is None and an empty string otherwise
-
relatives.utils.
object_link
(obj)¶ Return admin link to given object or blank text if no link
Equivalent to object_edit_link()(obj)
Template Tags¶
Return field contents or link to related object if foreign key field
Example Usage:
{% load relatives %} {{ field|contents_or_fk_link }}
Return list of objects related to the given model instance
Example Usage:
{% load relatives %} {% related_objects obj as related_objects %} {% for related_obj in related_objects %} <a href="{{ related_obj.url }}">{{ related_obj.plural_name }}</a> {% endfor %}