Skip to content

Commit

Permalink
Non-column attributes on child class overwrite column attributes of p…
Browse files Browse the repository at this point in the history
…arent class (fix #399) (#400)
  • Loading branch information
Dylan Verheul authored and jieter committed Dec 21, 2016
1 parent 13ff900 commit d8df96d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
/example/.env
/report.pylint
.cache/
.python-version
.idea
6 changes: 6 additions & 0 deletions django_tables2/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion example/requirements.pip
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-e ..
django-debug-toolbar
django-debug-toolbar<1.6
7 changes: 7 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d8df96d

Please sign in to comment.