diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-09-07 15:40:59 -0400 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-09-07 15:40:59 -0400 |
| commit | ca9c3cd39fade827cced1b5198dd37bb80c208b0 (patch) | |
| tree | 8a0a7d7c048d33798efa5baed8b51140a774bc90 /django/db/models/fields/__init__.py | |
| parent | 375178fc19c1170fe046ad26befeba02fc19548c (diff) | |
Add check constraint support - needed a few Field changes
Diffstat (limited to 'django/db/models/fields/__init__.py')
| -rw-r--r-- | django/db/models/fields/__init__.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 58ae3413f3..a0b09c9fec 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -232,12 +232,32 @@ class Field(object): # mapped to one of the built-in Django field types. In this case, you # can implement db_type() instead of get_internal_type() to specify # exactly which wacky database column type you want to use. + params = self.db_parameters(connection) + if params['type']: + if params['check']: + return "%s CHECK (%s)" % (params['type'], params['check']) + else: + return params['type'] + return None + + def db_parameters(self, connection): + """ + Replacement for db_type, providing a range of different return + values (type, checks) + """ data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_") try: - return (connection.creation.data_types[self.get_internal_type()] - % data) + type_string = connection.creation.data_types[self.get_internal_type()] % data except KeyError: - return None + type_string = None + try: + check_string = connection.creation.data_type_check_constraints[self.get_internal_type()] % data + except KeyError: + check_string = None + return { + "type": type_string, + "check": check_string, + } @property def unique(self): |
