Skip to content

Commit

Permalink
Fixed #28873 -- Used dict.setdefault() to set model and form field de…
Browse files Browse the repository at this point in the history
…faults.
  • Loading branch information
Дилян Палаузов authored and timgraham committed Dec 4, 2017
1 parent d2afa5e commit 87c76aa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions django/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -1678,7 +1678,7 @@ def __init__(self, verbose_name=None, name=None, path='', match=None,
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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/fields/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **k
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):
Expand Down
3 changes: 1 addition & 2 deletions django/db/models/fields/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,7 @@ def __init__(self, to, on_delete, related_name=None, related_query_name=None,
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)

Expand Down

0 comments on commit 87c76aa

Please sign in to comment.