Merged isinstance() calls.

This commit is contained in:
Mariusz Felisiak 2017-09-13 21:00:45 +02:00 committed by Tim Graham
parent c6a1faecc3
commit 0214f367bc
4 changed files with 4 additions and 4 deletions

View File

@ -134,7 +134,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
return self.formfield_for_choice_field(db_field, request, **kwargs) return self.formfield_for_choice_field(db_field, request, **kwargs)
# ForeignKey or ManyToManyFields # ForeignKey or ManyToManyFields
if isinstance(db_field, models.ManyToManyField) or isinstance(db_field, models.ForeignKey): if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
# Combine the field kwargs with any options for formfield_overrides. # Combine the field kwargs with any options for formfield_overrides.
# Make sure the passed in **kwargs override anything in # Make sure the passed in **kwargs override anything in
# formfield_overrides because **kwargs is more specific, and should # formfield_overrides because **kwargs is more specific, and should

View File

@ -394,7 +394,7 @@ def display_for_field(value, field, empty_value_display):
return dict(field.flatchoices).get(value, empty_value_display) return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes # NullBooleanField needs special-case null-handling, so it comes
# before the general null test. # before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField): elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
return _boolean_icon(value) return _boolean_icon(value)
elif value is None: elif value is None:
return empty_value_display return empty_value_display

View File

@ -83,7 +83,7 @@ class ArrayField(Field):
return '%s[%s]' % (self.base_field.db_type(connection), size) return '%s[%s]' % (self.base_field.db_type(connection), size)
def get_db_prep_value(self, value, connection, prepared=False): def get_db_prep_value(self, value, connection, prepared=False):
if isinstance(value, list) or isinstance(value, tuple): if isinstance(value, (list, tuple)):
return [self.base_field.get_db_prep_value(i, connection, prepared=False) for i in value] return [self.base_field.get_db_prep_value(i, connection, prepared=False) for i in value]
return value return value

View File

@ -837,7 +837,7 @@ class BaseModelFormSet(BaseFormSet):
pk_value = None pk_value = None
except IndexError: except IndexError:
pk_value = None pk_value = None
if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey): if isinstance(pk, (ForeignKey, OneToOneField)):
qs = pk.remote_field.model._default_manager.get_queryset() qs = pk.remote_field.model._default_manager.get_queryset()
else: else:
qs = self.model._default_manager.get_queryset() qs = self.model._default_manager.get_queryset()