All of the template tags¶
Listed below are reference materials for all the template tags considered public and suitable for use at this time. None are required.
Including shipped static assets¶
May be used in a template by adding the following line before calling any of them:
{% load adminlinks_assets %}
Or to put just some of the available tags in your template namespace you can do:
{% load render_adminlinks_js from adminlinks_assets %}
{% load render_adminlinks_css from adminlinks_assets %}
Asset tags¶
Rendering links to an admin site¶
May be used in a template by adding the following line before calling any of them:
{% load adminlinks_buttons %}
Or to put just some of the available tags in your template namespace you can do:
{% load render_edit_button from adminlinks_buttons %}
{% load render_changelist_button from adminlinks_buttons %}
and so on.
Link tags¶
An InclusionTag to render a link to the add_view() for a Model mounted onto a ModelAdmin on the AdminSite:
{% render_add_button my_class %} {% render_add_button my_class "my_custom_admin" %} {% render_add_button my_class "my_custom_admin" "a=1&b=2&a=3" %}
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model class to link to. Must have Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “_popup=1”
Returns: the link values.
Return type: dictionary.
Class for mixing into other classes to provide is_valid(), allowing subclasses to test the incoming data and react accordingly:
class MyContextHandler(BaseAdminLink): def get_context(self, context, obj): assert self.is_valid(context, obj) == True
Also provides base_options suitable for using in classy tags.
Default options involved in InclusionTag subclasses. Stored as a tuple because manipulating Options lists is more difficult than we’d like; see https://github.com/ojii/django-classy-tags/issues/14
Entry point for all subsequent tags. Tests the context and bails early if possible.
Performs some basic tests against the parameters passed to it to ensure that work should carry on afterwards.
Parameters: - context – a Context subclass, or dictionary-like object which fulfils certain criteria. Usually a RequestContext.
- obj – the Model, either as a class or an instance. Or, more specifically, anything which as a Options object stored under the _meta attribute.
Returns: whether or not the context and object pair are valid.
Return type: See also
An InclusionTag to render a link to the changelist_view() (paginated objects) for a ModelAdmin instance:
{% render_changelist_button my_class %} {% render_changelist_button my_class "my_custom_admin" %} {% render_changelist_button my_class "my_custom_admin" "a=1&b=2&a=3" %}
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model class to link to. Must have Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “pop=1” unless Django > 1.6, when it changes to “_popup=1”
Returns: the link values.
Return type: dictionary.
This needs reworking, I think.
Wraps all the other adminlink template tags into one.
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model class to link to. Must have Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
Returns: the link values.
Return type: dictionary.
An InclusionTag to render a link to the delete confirmation form for an object:
{% render_delete_button my_obj %} {% render_delete_button my_obj "my_custom_admin" %} {% render_delete_button my_obj "my_custom_admin" "a=1&b=2&a=3" %}
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model instance to link to. Must have a primary key, and Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “_popup=1”
Returns: the link values.
Return type: dictionary.
An InclusionTag to render a link to the admin change form for an object:
{% render_edit_button my_obj %} {% render_edit_button my_obj "my_custom_admin" %} {% render_edit_button my_obj "my_custom_admin" "a=1&b=2&a=3" %}
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model instance to link to. Must have a primary key, and Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “_popup=1”
Returns: the link values.
Return type: dictionary.
An InclusionTag to render a link to a customised admin change form for an object, showing only the requested field:
{% render_edit_field_button my_obj "field_name" %} {% render_edit_field_button my_obj "field_name" "my_custom_admin" %} {% render_edit_field_button my_obj "field_name" "my_custom_admin" "a=1&b=2&a=3" %}
Note
Use of this class requires that the ModelAdmin includes AdminlinksMixin or otherwise creates a named url ending in change_field.
Changed in version 0.8.1: The default template, adminlinks/edit_field_link.html now expects to be able to use {% load static %} if the field being edited is either a BooleanField or a NullBooleanField, so that it can render an icon.
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model instance to link to. Must have a primary key, and Options from which we can retrieve a verbose_name
- fieldname – the specific model field to render a link for.
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “_popup=1”
Returns: the link values.
Return type: dictionary.
An InclusionTag to render a link to the object’s history_view() in a ModelAdmin instance:
{% render_history_button my_obj %} {% render_history_button my_obj "my_custom_admin" %} {% render_history_button my_obj "my_custom_admin" "a=1&b=2&a=3" %}
Adds a link and verbose_name to the context, if is_valid()
Parameters: - context – Hopefully, a RequestContext otherwise is_valid() is unlikely to be True
- obj – the Model instance to link to. Must have a primary key, and Options from which we can retrieve a verbose_name
- admin_site – name of the admin site to use; defaults to “admin”
- querystring – a querystring to include in the link output. Defaults to “_popup=1”
Returns: the link values.
Return type: dictionary.
what gets rendered by this tag.