I have a model in which there are two fields, one characterized by the element position on the X coordinate of the second Y
class Task(models.Model):
posx = models.IntegerField(blank = True, null = True, verbose_name='X coordinate')
posy = models.IntegerField(blank = True, null = True, verbose_name='Y coordinate')
Visuall开发者_如何学JAVAy, it looks like this
|1|2|3|4|5|
1 x
2 x x x x
3 x x
4
5
Now the question is, how do I get it properly in html table where there are empty blocks is not empty.
If you do so
Tlist=Task.objects.filter(proj=proj).order_by('posy',)
Then the derivation of a pattern I can not understand where is the end of rows in the table.
Use this to generate the table as a list of lists (two dimensional array), then pass it to your template:
def get_table(proj, max_x, max_y):
table = [[False for x in xrange(max_x)] for y in xrange(max_y)]
tasks = Task.objects.filter(proj=proj)
for task in tasks:
table[task.posy-1][task.posx-1] = True
return table
(Edit: fixed zero index bug)
精彩评论