Fixed #28873 -- Used dict.setdefault() to set model and form field defaults.

This commit is contained in:
Дилян Палаузов 2017-12-04 10:52:27 -05:00 committed by Tim Graham
parent d2afa5eb23
commit 87c76aa116
3 changed files with 5 additions and 6 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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)