Commits

Javed Khan committed d41ec53

handle multiple relations

  • Participants
  • Parent commits 892964f

Comments (0)

Files changed (3)

File schema/templates/schema/object_list.html

 {% extends "base.html" %}
+{% load schema_tags %}
 {% block content %}
-<div class="span4">
+<div class="span8">
     {% if objects %}
     <table class="table table-striped table-hover table-bordered" cellspacing="0">
         {% for object in objects %}
             <td><strong>{{ attr.key }}</strong></td>
             <td>{{ attr.value }}</td>
             {% endfor %}
-            {% if object.related.count %}
-            <td>
-                <strong>Related {{ object.related.all.0.model }}</strong>
-            </td>
+            {% for model in object.model.model_set.all %}
+            <td><strong>Related {{ model.name }}</strong></td>
             <td>
                 <ol>
-                    {% for rel in object.related.all %}
+                    {% for rel in object.related.all|filter:model %}
                     <li>{{ rel }}</li>
                     {% endfor %}
                 </ol>
             </td>
-            {% endif %}
+            {% endfor %}
         </tr>
         {% endfor %}
     </table>

File schema/templatetags/__init__.py

Empty file added.

File schema/templatetags/schema_tags.py

+from django import template
+
+register = template.Library()
+
+@register.filter
+def filter(qs, model):
+    return qs.filter(model=model)