Django-tables2: Change text displayed in column title

后端 未结 1 696
小鲜肉
小鲜肉 2021-01-17 17:12

I am working with a MySQL view (Create View as Select ...) and have successfully manged to connect the view to a model like this:

#models.py
class Dashboard(         


        
1条回答
  •  执笔经年
    2021-01-17 17:49

    Just add the columns whose names you want to override in your tables.py. For instance

    #tables.py
    import django_tables2 as tables
    from models import Dashboard
    
    class DashboardTable(tables.Table):
      devenv = tables.Column(verbose_name= 'Development Environment' )
    
      class Meta:
        model = Dashboard
        attrs = {'class': 'paleblue'}
    

    Another (probably more DRY) solution is to leave tables.py as is and add verbose_name in your model definition:

    #models.py
    class Dashboard(models.Model):
        devenv = models.CharField(max_length=30, primary_key=True, verbose_name='Development Environment')
        numberofissues = models.BigIntegerField(verbose_name='Number of Issues')
        class Meta:
            managed=False
            db_table = 'stability_dashboard'
    

    0 讨论(0)
提交回复
热议问题