Skip to content

Commit a3546ac

Browse files
committed
Documentation update
1 parent 0437b3b commit a3546ac

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

docs/extending_cms/frontend_models.rst

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add ``show_editable_model``::
2929
<h1>{% show_editable_model instance "some_attribute" %}</h1>
3030
{% endblock content %}
3131

32-
See `templatetag reference <show_editable_model_reference>`_ for description of arguments.
32+
See `templatetag reference <show_editable_model_reference>`_ for arguments documentation.
3333

3434
********************
3535
Selected fields edit
@@ -80,25 +80,43 @@ the model, you can also use a property or a method as a target.
8080
Custom views
8181
************
8282

83-
You can link any field to a custom view (not necessarily an admin view); in any
84-
case your view does not need to obey any specific interface, other than
85-
possibly check to ``_popup`` query string parameter to select a popup-enabled
86-
template.
83+
You can link any field to a custom view (not necessarily an admin view) to handle
84+
model-specific editing workflow.
8785

88-
Custom views can be specified by either passing the ``view_url`` attribute
89-
(which will be passed to the ``reverse`` function with the instance ``pk`` and
90-
``language`` arguments) or by using the ``view_method`` to pass a method
91-
(or property) of the model instance; this property / method must return
92-
a complete URL.
86+
The custom view can be passed either as a named url (``view_url``) or as name
87+
(``view_method``) of a method (or property) on the instance being edited.
88+
In case you provide ``view_method`` it will be called whenever the templatetag is
89+
evaluated with ``request`` as first parameter.
9390

94-
Example::
91+
The custom view does not need to obey any specific interface, but it will get
92+
``edit_fields`` value as a ``GET`` parameter.
93+
94+
See `templatetag reference <show_editable_model_reference>`_ for arguments documentation.
95+
96+
Example ``view_url``::
9597

9698
{% load placeholder_tags %}
9799

98100
{% block content %}
99101
<h1>{% show_editable_model instance "some_attribute" "some_field,other_field" "" "admin:exampleapp_example1_some_view" %}</h1>
100102
{% endblock content %}
101103

104+
105+
Example ``view_method``::
106+
107+
class MyModel(models.Model):
108+
char = models.CharField(max_length=10)
109+
110+
def some_method(self, request):
111+
return "/some/url"
112+
113+
114+
{% load placeholder_tags %}
115+
116+
{% block content %}
117+
<h1>{% show_editable_model instance "some_attribute" "some_field,other_field" "" "some_method" %}</h1>
118+
{% endblock content %}
119+
102120
.. _show_editable_model_reference:
103121

104122
*********************
@@ -125,8 +143,9 @@ Arguments:
125143
* ``language`` (optional): the admin language tab to be linked. Useful only for
126144
`django-hvad`_ enabled models.
127145
* ``view_url`` (optional): the name of a url that will be reversed using the
128-
instance ``pk`` and the ``attribute`` (or ``edit_field``) as arguments;
146+
instance ``pk`` and the ``language`` as arguments;
129147
* ``view_method`` (optional): a method name that will return a URL to a view;
148+
the method must accept ``request`` as first parameter.
130149

131150

132-
.. _django-hvad: https://github.com/kristianoellegaard/django-hvad
151+
.. _django-hvad: https://github.com/kristianoellegaard/django-hvad

0 commit comments

Comments
 (0)