From d8df96d30f64da48d2788e09748f8b6d97ba292b Mon Sep 17 00:00:00 2001 From: Dylan Verheul Date: Wed, 21 Dec 2016 19:20:54 +0100 Subject: [PATCH] Non-column attributes on child class overwrite column attributes of parent class (fix #399) (#400) --- .gitignore | 2 ++ django_tables2/tables.py | 6 ++++++ example/requirements.pip | 2 +- tests/test_core.py | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c66f7a8..a99b91e7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ /example/.env /report.pylint .cache/ +.python-version +.idea \ No newline at end of file diff --git a/django_tables2/tables.py b/django_tables2/tables.py index b635d833..55a53ed4 100644 --- a/django_tables2/tables.py +++ b/django_tables2/tables.py @@ -210,11 +210,17 @@ def __new__(mcs, name, bases, attrs): # Explicit columns override both parent and generated columns base_columns.update(OrderedDict(cols)) + # Apply any explicit exclude setting for exclusion in opts.exclude: if exclusion in base_columns: base_columns.pop(exclusion) + # Remove any columns from our remainder, else columns from our parent class will remain + for attr_name in remainder: + if attr_name in base_columns: + base_columns.pop(attr_name) + # Reorder the columns based on explicit sequence if opts.sequence: opts.sequence.expand(base_columns.keys()) diff --git a/example/requirements.pip b/example/requirements.pip index 45530193..f8fe87fa 100644 --- a/example/requirements.pip +++ b/example/requirements.pip @@ -1,2 +1,2 @@ -e .. -django-debug-toolbar +django-debug-toolbar<1.6 diff --git a/tests/test_core.py b/tests/test_core.py index 98b45329..916564de 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -77,6 +77,13 @@ class CityTable(GeoAreaTable, AddedMixin): assert len(CityTable.base_columns) == 4 assert 'added' in CityTable.base_columns + # overwrite a column with a non-column + class MayorlessCityTable(CityTable): + mayor = None + + assert len(MayorlessCityTable.base_columns) == 3 + + def test_metaclass_inheritance(): class Tweaker(type):