A
A
admin4eg2013-09-17 12:13:48
Django
admin4eg, 2013-09-17 12:13:48

result table output problem

Good day, I haven’t kneaded my head for a long time. now I don’t know how to “Django way” solve such a problem.

There are competitions, there is a set of points (point) on which the judges (moderator) stand, the judge notes that the crew (bortn) passed the point at such and such a time.
everything here is simple and clear.
Until we impose such a condition.

The moderator is not always able to mark the position of the crew on the site in time.
it may turn out that the first mark on the site for the crew, for example 888, will be only at number 5.

and the table should be displayed approximately like this


. The whole question arises in the correct placement of the template in the html.

in Views.py I get all members something like this

...... 
         bn = bort.objects.all()
        context['items'] = bn
        return context


there is a similar model
class bort(models.Model):
    bortn = models.IntegerField(verbose_name=u'Бортовой номер')
    comment = models.CharField(max_length=200, verbose_name=u'Комментарий' )

#Получаю все результаты для участника
    def alltime(self):
        at = ktime.objects.filter(borts=self)



class ktime(models.Model):
 KV_CHOICES = (
        (0, u'kv0'),
        (1, u'kv1'),
        ......
        )
    point = models.IntegerField(max_length=200,choices=KV_CHOICES, verbose_name=u'Точка')
    borts = models.ForeignKey(bort,verbose_name=u'Бортовой номер')
    chas = models.CharField(max_length=15,choices=Hor_CHOICES, verbose_name=u'Часы' )
    min = models.CharField(max_length=15, choices=Min_CHOICES, verbose_name=u'Минуты' )
    author = models.ForeignKey(User, null = True, blank = True , verbose_name=u'Модератор')

    def get_time(self):
        return u'%s:%s' %(self.chas, self.min)

    class Meta:
        verbose_name = 'Контроль времени'
        verbose_name_plural = 'Контроль времени'

    class Admin:
        pass

    def __unicode__(self):
        return u'точка %s - борт %s - время %s : %s' % (self.point, self.borts, self.chas, self.min)


as a result, without any dances, we get this picture, I noted in red, then where the time stamp should be,


if it is displayed in the template like this

<table>
     <tr>
         <td>№   /  Точка</td><td>kv1</td><td>kv2</td><td>kv3</td><td>kv4</td><td>kv5</td>
     </tr>
     {%  for p in items %}
        <tr>
            <td>{{ p.bortn }}</td>
                {% for is in p.alltime %}
                    <td>  {{ is.get_time }} </td>
                {% endfor  %}
        </tr>
    {% endfor %}
</table>


then I got carried away the wrong way, I tried to add another cycle inside and check if the step of the inner cycle == id point then they say we draw. time otherwise draw empty ... something like this

{% for x in 'xxxxxxx' %}
    {% if forloop.counter0 == is.point %}
       <td>  {{ is.get_time }} </td>
    {% else %}
       <td> </td>
    {% endif %}
{% endfor %}


but this is all fundamentally wrong, because I can’t interrupt the cycle after a successful result either ...

in general, the question arises how to go further? maybe the model is wrong for such an organization of the output of the result, maybe I don’t even understand it right ...
I was already thinking about how to fill something like a matrix (two-dimensional array) with the results of empty cells 0 and enter the time into the result.
generally asking for advice

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alz, 2013-09-17
@alz

Arrange the timestamps as you need in the view, don't try to achieve this in templates
Arrange everything first in dictionaries, then use them to form lists of timestamps

P
Pavel Zagrebelin, 2013-09-19
@Zagrebelion

If the number of points is limited, then output to your span every time:

<div>
<span class="point_1">12:20</span>
<span class="point_3">13:40</span>
</div>

and in css set different margins for point_n classes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question