Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
morlandi committed Sep 26, 2018
1 parent 916a2c2 commit 151911c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions docs/source/topics/frontend_generic_helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ forniscono direttamente il link "canonico":

.. code:: python
@register.filter
def add_model_url(model):
"""
Given a model, return the "canonical" url for adding a new object:
<a href="{{model|add_model_url}}">add a new object</a>
"""
return reverse('frontend:object-add', args=(model._meta.app_label, model._meta.model_name))
@register.filter
def change_object_url(object):
"""
Expand All @@ -171,22 +181,18 @@ forniscono direttamente il link "canonico":
return reverse('frontend:object-change', args=(model._meta.app_label, model._meta.model_name, object_id))
@register.filter
def add_model_url(model):
"""
Given a model, return the "canonical" url for adding a new object:
<a href="{{model|add_model_url}}">add a new object</a>
"""
return reverse('frontend:object-add', args=(model._meta.app_label, model._meta.model_name))
e riscrivere il template piu' semplicemente come segue::

{# add object #}
data-action="{{model|add_model_url}}"

{# change object #}
data-action="{{model|change_model_url:object.id}}"

{# add object #}
data-action="{{model|add_model_url}}"
oppure:

{# change object #}
data-action="{{object|change_object_url}}"


Deleting an object
Expand Down

0 comments on commit 151911c

Please sign in to comment.