diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 808f4709ac..32b30a7e8b 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -134,7 +134,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass): return self.formfield_for_choice_field(db_field, request, **kwargs) # 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. # Make sure the passed in **kwargs override anything in # formfield_overrides because **kwargs is more specific, and should diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 5f3a83267d..9bd4aa7857 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -394,7 +394,7 @@ def display_for_field(value, field, empty_value_display): return dict(field.flatchoices).get(value, empty_value_display) # NullBooleanField needs special-case null-handling, so it comes # 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) elif value is None: return empty_value_display diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index d418e1dc1a..7992740663 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -83,7 +83,7 @@ class ArrayField(Field): return '%s[%s]' % (self.base_field.db_type(connection), size) 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 value diff --git a/django/forms/models.py b/django/forms/models.py index 4435bf9722..ef934201a9 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -837,7 +837,7 @@ class BaseModelFormSet(BaseFormSet): pk_value = None except IndexError: 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() else: qs = self.model._default_manager.get_queryset()