Skip to content

Commit a309c5d

Browse files
committed
Allow string model names
1 parent 7c67edf commit a309c5d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

dbdiff/tests/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from dbdiff.utils import get_model_names
2+
3+
from django.contrib.auth.models import Group
4+
5+
6+
def test_get_model_names():
7+
assert get_model_names([Group, 'auth.user']) == ['auth.group', 'auth.user']

dbdiff/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from django.apps import apps
77
from django.db import connections
88

9+
import six
10+
911

1012
def get_tree(dump, exclude=None):
1113
"""Return a tree of model -> pk -> fields."""
@@ -90,8 +92,11 @@ def get_absolute_path(path):
9092

9193
def get_model_names(model_classes):
9294
"""Return model names for model classes."""
93-
return ['%s.%s' % (m._meta.app_label, m._meta.model_name)
94-
for m in model_classes]
95+
return [
96+
m if isinstance(m, six.string_types)
97+
else '%s.%s' % (m._meta.app_label, m._meta.model_name)
98+
for m in model_classes
99+
]
95100

96101

97102
def get_models_tables(models):

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ passenv = TEST_* DBDIFF_*
3333
basepython = python2.7
3434
commands =
3535
flake8 --show-source --exclude tests --max-complexity=7 --ignore=D203 dbdiff
36-
flake8 --show-source --exclude migrations --max-complexity=3 --ignore=D100,D101,D102 dbdiff/tests
36+
flake8 --show-source --exclude migrations --max-complexity=3 --ignore=D100,D101,D102,D103 dbdiff/tests
3737

3838
deps =
3939
flake8

0 commit comments

Comments
 (0)