File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ class App(object):
24
24
def __init__ (self , name ):
25
25
self .name = name
26
26
self .verbose_name = _ (name .title ())
27
- self .verbose_name_plural = _ (name .title ())
28
27
self .db_prefix = name
29
28
self .errors = []
30
29
self .models = []
@@ -97,6 +96,16 @@ def _populate(self):
97
96
% app_label )
98
97
for model in models .itervalues ():
99
98
app_instance .models .append (model )
99
+ # check if there is more than one app with the same
100
+ # db_prefix attribute
101
+ for app in self .app_instances :
102
+ for app_cmp in self .app_instances :
103
+ if app != app_cmp and \
104
+ app .db_prefix == app_cmp .db_prefix :
105
+ raise ImproperlyConfigured (
106
+ 'The apps "%s" and "%s" have the same '
107
+ 'db_prefix "%s"'
108
+ % (app , app_cmp , app .db_prefix ))
100
109
self .loaded = True
101
110
self .unbound_models = {}
102
111
finally :
Original file line number Diff line number Diff line change @@ -6,3 +6,7 @@ class MyApp(App):
6
6
def __repr__ (self ):
7
7
return '<MyApp: %s>' % self .name
8
8
9
+ class MyOtherApp (MyApp ):
10
+ def __init__ (self , name ):
11
+ super (MyOtherApp , self ).__init__ (name )
12
+ self .db_prefix = 'nomodel_app'
Original file line number Diff line number Diff line change @@ -97,6 +97,14 @@ def test_empty_models(self):
97
97
self .assertEqual (cache .get_apps (), [])
98
98
self .assertTrue (cache .app_cache_ready ())
99
99
100
+ def test_db_prefix_exception (self ):
101
+ """
102
+ Test that an exception is raised if two app instances
103
+ have the same db_prefix attribute
104
+ """
105
+ settings .INSTALLED_APPS = ('nomodel_app.MyApp' , 'model_app.MyOtherApp' ,)
106
+ self .assertRaises (ImproperlyConfigured , cache .get_apps )
107
+
100
108
class GetAppTests (AppCacheTestCase ):
101
109
"""Tests for the get_app function"""
102
110
You can’t perform that action at this time.
0 commit comments