/ Published in: Django
First: create a file under djangoapp/templatetags where you define your tags [e.g.: myadmin_tags.py]:
Second: create the html snippets that get loaded in those tags [e.g., personfactoid_info.html]:
Third: in mytemplates/admin/ modify change_form.html (if you don't have it just copy it from the django-admin app). You must add a placeholder for the new templatetags (probably you want to add it at the bottom of the page):
FOurth: create a new change_form.html in the same directory as above, but under your model template [e.g., mytemplates/admin/myapp/mymodel/change_form.html] so to override the behaviour just for that. The 'object_id' variable is passed by the admin template by default:
Second: create the html snippets that get loaded in those tags [e.g., personfactoid_info.html]:
Third: in mytemplates/admin/ modify change_form.html (if you don't have it just copy it from the django-admin app). You must add a placeholder for the new templatetags (probably you want to add it at the bottom of the page):
FOurth: create a new change_form.html in the same directory as above, but under your model template [e.g., mytemplates/admin/myapp/mymodel/change_form.html] so to override the behaviour just for that. The 'object_id' variable is passed by the admin template by default:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# FIRST: from django import template from poms.pomsapp import models register = template.Library() # for People template @register.inclusion_tag('admin/snippets/personfactoid_info.html') def display_personfactoids(person_id): person = models.Person.objects.get(id__exact=person_id) # factoids = models.Factoids.objects.filter(people=person) return { 'person': person } ## SECOND: {% if person.assocfactoidperson_set.all %} <b>Person associated to factoids:</b></br /> <table> <tr> <th>Record ID</th> <th>Type</th> <th>Short Summary</th> <th>Role</th> <th>Source</th> </tr> {% for a in person.assocfactoidperson_set.all %} <tr> <td>{{a.factoid.id}}</td> <td>{{a.factoid.get_right_subclass.0}}    </td> <td><a href="{% url factoid_detail a.factoid.id %}" title="click to show">{{a.factoid}}</a></td> <td>{{a.role}}</td> <td><a href="{% url source_detail a.factoid.sourcekey.id %}" title="click to show">{{a.factoid.sourcekey}}</a></td> </tr> {% endfor %} </table> <br /><hr><hr><hr><br /> {% endif %} ## THIRD ........ {% block related_items_block %}{% endblock %} ........ ## FOURTH {% extends "admin/change_form.html" %} {% load myadmin_tags %} {% block related_items_block %} <h2>Additional information:</h2><br /> {% if object_id %} {% display_personfactoids object_id %} {% endif %} {% endblock %}