summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorAdrian Torres <atorresj@redhat.com>2022-11-10 19:31:31 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-28 12:31:04 +0100
commit7eee1dca420ee7c4451d24cd32fa08aed0dcbb36 (patch)
treef643059561e9699cc961845f63faf0a3664ff5d0 /django/db/models
parent78f163a4fb3937aca2e71786fbdd51a0ef39629e (diff)
Fixed #14094 -- Added support for unlimited CharField on PostgreSQL.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/fields/__init__.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index e3b47d173c..060e1be605 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -817,9 +817,14 @@ class Field(RegisterLookupMixin):
# exactly which wacky database column type you want to use.
data = self.db_type_parameters(connection)
try:
- return connection.data_types[self.get_internal_type()] % data
+ column_type = connection.data_types[self.get_internal_type()]
except KeyError:
return None
+ else:
+ # column_type is either a single-parameter function or a string.
+ if callable(column_type):
+ return column_type(data)
+ return column_type % data
def rel_db_type(self, connection):
"""
@@ -1130,14 +1135,19 @@ class BooleanField(Field):
class CharField(Field):
- description = _("String (up to %(max_length)s)")
-
def __init__(self, *args, db_collation=None, **kwargs):
super().__init__(*args, **kwargs)
self.db_collation = db_collation
if self.max_length is not None:
self.validators.append(validators.MaxLengthValidator(self.max_length))
+ @property
+ def description(self):
+ if self.max_length is not None:
+ return _("String (up to %(max_length)s)")
+ else:
+ return _("String (unlimited)")
+
def check(self, **kwargs):
databases = kwargs.get("databases") or []
return [
@@ -1148,6 +1158,12 @@ class CharField(Field):
def _check_max_length_attribute(self, **kwargs):
if self.max_length is None:
+ if (
+ connection.features.supports_unlimited_charfield
+ or "supports_unlimited_charfield"
+ in self.model._meta.required_db_features
+ ):
+ return []
return [
checks.Error(
"CharFields must define a 'max_length' attribute.",