From 87c76aa116ef49be2d6ff3ecf2fec37414638246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Mon, 4 Dec 2017 10:52:27 -0500 Subject: [PATCH] Fixed #28873 -- Used dict.setdefault() to set model and form field defaults. --- django/db/models/fields/__init__.py | 6 +++--- django/db/models/fields/files.py | 2 +- django/db/models/fields/related.py | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 4a006bc85d..1e3db7e776 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1652,7 +1652,7 @@ class EmailField(CharField): def __init__(self, *args, **kwargs): # max_length=254 to be compliant with RFCs 3696 and 5321 - kwargs['max_length'] = kwargs.get('max_length', 254) + kwargs.setdefault('max_length', 254) super().__init__(*args, **kwargs) def deconstruct(self): @@ -1678,7 +1678,7 @@ class FilePathField(Field): recursive=False, allow_files=True, allow_folders=False, **kwargs): self.path, self.match, self.recursive = path, match, recursive self.allow_files, self.allow_folders = allow_files, allow_folders - kwargs['max_length'] = kwargs.get('max_length', 100) + kwargs.setdefault('max_length', 100) super().__init__(verbose_name, name, **kwargs) def check(self, **kwargs): @@ -2258,7 +2258,7 @@ class URLField(CharField): description = _("URL") def __init__(self, verbose_name=None, name=None, **kwargs): - kwargs['max_length'] = kwargs.get('max_length', 200) + kwargs.setdefault('max_length', 200) super().__init__(verbose_name, name, **kwargs) def deconstruct(self): diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index d14da97cce..00dcbc033c 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -226,7 +226,7 @@ class FileField(Field): self.storage = storage or default_storage self.upload_to = upload_to - kwargs['max_length'] = kwargs.get('max_length', 100) + kwargs.setdefault('max_length', 100) super().__init__(verbose_name, name, **kwargs) def check(self, **kwargs): diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index db0558b5ed..cfb5ea1ef6 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -808,8 +808,7 @@ class ForeignKey(ForeignObject): parent_link=parent_link, on_delete=on_delete, ) - - kwargs['db_index'] = kwargs.get('db_index', True) + kwargs.setdefault('db_index', True) super().__init__(to, on_delete, from_fields=['self'], to_fields=[to_field], **kwargs)