我正在使用 MySQL 视图(Create View as Select ...),并成功地将视图连接到这样的模型:
#models.py
class Dashboard(models.Model):
devenv = models.CharField(max_length=30, primary_key=True)
numberofissues = models.BigIntegerField()
class Meta:
managed=False
db_table = 'stability_dashboard'
我还设法使用示例中的样板代码在表格中显示数据:
#tables.py
class DashboardTable(tables.Table):
class Meta:
model = Dashboard
attrs = {'class': 'paleblue'}
#views.py
def dashboard(request):
table = DashboardTable(Dashboard.objects.all())
RequestConfig(request).configure(table)
return render(request, 'uptime/dash.html', {'table': table})
我现在想将每列中显示的标题更改为更易于理解的内容,包括空格,例如,而不是 'devenv' => 'Development Environment'