Code

Ticket #15238: patch.diff

File patch.diff, 1.6 KB (added by dgl, 3 years ago)

first patch

Line 
1diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
2index 0a45d75..7a128d9 100644
3--- a/django/conf/global_settings.py
4+++ b/django/conf/global_settings.py
5@@ -583,3 +583,5 @@ STATICFILES_FINDERS = (
6 # Make sure to use a trailing slash.
7 # Examples: "http://foo.com/static/admin/", "/static/admin/".
8 ADMIN_MEDIA_PREFIX = '/static/admin/'
9+
10+TABLE_PREFIX = None
11diff --git a/django/db/models/options.py b/django/db/models/options.py
12index 2f64c56..1bb32f4 100644
13--- a/django/db/models/options.py
14+++ b/django/db/models/options.py
15@@ -108,6 +108,8 @@ class Options(object):
16         # If the db_table wasn't provided, use the app_label + module_name.
17         if not self.db_table:
18             self.db_table = "%s_%s" % (self.app_label, self.module_name)
19+            if settings.TABLE_PREFIX:
20+                self.db_table = "%s_%s" % (settings.TABLE_PREFIX, self.db_table)
21             self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
22 
23     def _prepare(self, model):
24diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
25index 8bf0a4e..b72eb92 100644
26--- a/docs/ref/settings.txt
27+++ b/docs/ref/settings.txt
28@@ -1680,6 +1680,19 @@ It must end in a slash if set to a non-empty value.
29 
30 See :setting:`STATIC_ROOT`.
31 
32+.. setting:: TABLE_PREFIX
33+
34+TABLE_PREFIX
35+----------
36+
37+Default: ``None``
38+
39+Prefix that will be added to all table names, if db_table property is not set
40+explicitly.
41+
42+By default Django generates table name concatenating application name and
43+model name. If not ``None``, this will be prepended to the result.
44+
45 .. setting:: TEMPLATE_CONTEXT_PROCESSORS
46 
47 TEMPLATE_CONTEXT_PROCESSORS