Return to Snippet

Revision: 21844
at December 22, 2009 15:06 by magicrebirth

Initial Code

from django import template 
from poms.pomsapp import models

register = template.Library() 

# for People template

def display_personfactoids(person_id): 
    person = models.Person.objects.get(id__exact=person_id) 
    # factoids = models.Factoids.objects.filter(people=person)
    return { 'person': person }


{% if person.assocfactoidperson_set.all %}

<b>Person associated to factoids:</b></br />

	    <th>Record ID</th>
	    <th>Short Summary</th>

	{% for a in person.assocfactoidperson_set.all %}
	    <td><a href="{% url factoid_detail %}" title="click to show">{{a.factoid}}</a></td>
	    <td><a href="{% url source_detail %}" title="click to show">{{a.factoid.sourcekey}}</a></td>
	{% endfor %}

	<br /><hr><hr><hr><br />
{% endif %}



{% block related_items_block %}{% endblock %}



{% 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 %}

Initial URL

Initial Description
First: create a file under djangoapp/templatetags where you define your tags [e.g.:]:

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:

Initial Title
Django: adding new admin_tags

Initial Tags
python, django

Initial Language