Answer the question
In order to leave comments, you need to log in
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
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)
<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>
{% for x in 'xxxxxxx' %}
{% if forloop.counter0 == is.point %}
<td> {{ is.get_time }} </td>
{% else %}
<td> </td>
{% endif %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
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
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>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question