From 31963d99b80cacaa781b7e3934a6e95f0b469c6e Mon Sep 17 00:00:00 2001 From: Harro van der Klauw Date: Tue, 12 Oct 2010 11:15:56 +0200 Subject: [PATCH] Added verbose_name to columns from a model. --- django_tables/models.py | 2 +- tests/test_models.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/django_tables/models.py b/django_tables/models.py index 17fd40e..b3ccb09 100644 --- a/django_tables/models.py +++ b/django_tables/models.py @@ -33,7 +33,7 @@ def columns_for_model(model, columns=None, exclude=None): if (columns and not f.name in columns) or \ (exclude and f.name in exclude): continue - column = Column() # TODO: chose correct column type, with right options + column = Column(verbose_name=f.verbose_name) # TODO: chose correct column type, with right options if column: field_list.append((f.name, column)) field_dict = SortedDict(field_list) diff --git a/tests/test_models.py b/tests/test_models.py index 867ba30..c87b142 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -103,6 +103,16 @@ class TestDeclaration: columns = ('system', 'population', 'foo', 'tld',) assert [c.name for c in CountryTable().columns] == ['system', 'population', 'foo', 'tld'] + + def test_columns_verbose_name(self): + """Tests that the model field's verbose_name is used for the column + """ + class CountryTable(tables.ModelTable): + class Meta: + model = Country + columns = ('tld',) + + assert [c.verbose_name for c in CountryTable.columns] = ['Domain Extension'] def test_basic(): -- 2.26.2