There is a model:
class DomainPosition(models.Model):
domain = models.ForeignKey(Domain)
keyword = models.ForeignKey(Keyword)
date = models.DateField()
position = models.IntegerField()
class Meta:
ordering = ['domain', 'keyword']
How to get the data for a template? For each domain want to display table (figures in table - position):
+----------+--------+--------+-------+--------
| keyword | date1 | date2 | date3 | ...
+----------+--------+--------+-------+--------
| keyword1 | 2 | 6 | 7 | ...
+----------+--------+--------+-------+--------
| keyword2 | 4 | 12 | 5 | ...
+----------+--------+--------+-------+--------
| keyword3 | 6 | 3 | 9 | ...
+----------+--------+--------+-------+--------
views.py:
def show_domain_history(request, domain_name):
domain = Domain.objects.filter(name__contains=domain_name)
if not domain:
return HttpResponseRedirect('/')
else:
# positions = ...
variables = RequestContext(request, {
'domain': domain[0].name,
'positions': positions,
})
return render_to_response('history.html', variables)
How to get positions?