I have a model, which is defined as shown, which acts on the query and gets a list of objects that should be placed in the corresponding cells of the table. Here is the relevant piece of code.
class Location(models.Model):
x=models.IntegerField(null=True)
y=models.IntegerField(null=True)
z=models.CharField(max_length=5,null=True)
def __unicode__(self):
return self.z
From this db, I want to get all the objects and put them in a 2d table with the row and column defined by x, y of this object. If there is no specific object (x, y), then this particular interval should be displayed empty in the table. This is an opinion that I wrote to meet these goals.
def gettable(request):
events=[]
for xdim in xrange(3):
xe=[]
for ydim in xrange(3):
object=[0]
object.append(Location.objects.filter(x=xdim,y=ydim))
xe.append(object[-1])
events.append(xe)
return render(request, 'scheduler/table.html', {'events':events})
Here is the html part of the code
<table border="1">
<th>Header 0</th>
<th>Header 1</th>
<th>Header 2</th>
{% for event in events %}
<tr>
{% for x in event %} <td>{{ x }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
I need to solve a few problems here.
1. ( , , django ), , , (x, y ) .
2. [<Location: 21>], , "21".
3. , - (x, y).
4., , .