You could also put a columns property onto each person object.

Given the models:

class Person(models.Model):
    name = models.CharField(max_length=30)

class DataPoint(models.Model):
    person = models.ForeignKey(Person)
    value = models.IntegerField()

and a view named list:

def list(request):
    people = Person.objects.all()
    for p in people:
        p.columns = [None, None, None]
        for c in DataPoint.objects.filter(person=p, value__gt=4):
            p.columns.append(c)

    return render_to_response('people/listing.html',
dict(people=people))

(the columns property above is a bit contrived, I think given your
situation--needing a certain number of columns--you'd need some logic
to put None into columns whose DB value was greater than what you
wanted, that way each person's columns property has the same number of
elements and things will line up)

You could then have a pretty simple view:

        <table><thead></thead>
            <tbody>
                {% for person in people %}
                    <tr>
                        <th>{{ person.name }}</th>
                        {% for col in person.columns %}
                            {% if col %}
                                <td>{{ col.value }}</td>
                            {% else %}
                                <td>(blank)</td>
                            {% endif %}
                        {% endfor %}
                    </tr>
                {% endfor %}
            </tbody>
        </table>


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to