remove get_field_by_name calls (#24857)

This commit is contained in:
Emmanuel Cazenave 2018-06-28 16:52:35 +02:00
parent a4a74ea1a3
commit 88ae29f099
4 changed files with 8 additions and 6 deletions

View File

@ -34,7 +34,7 @@ def get_attribute_names(instance, ctx):
name = 'django_user_' + str(attribute.name)
description = attribute.label + u' (%s)' % name
yield name, description
group_label = User._meta.get_field_by_name('groups')[0].verbose_name
group_label = User._meta.get_field('groups').verbose_name
yield 'django_user_groups', group_label + u' (django_user_groups)'
yield 'django_user_group_names', group_label + u' (django_user_group_names)'
yield 'django_user_domain', _('User domain') + u' (django_user_domain)'

View File

@ -371,7 +371,7 @@ class LibertyProvider(Service):
verbose_name_plural = _('SAML providers')
def get_all_custom_or_default(instance, name):
model = instance._meta.get_field_by_name(name)[0].rel.to
model = instance._meta.get_field(name).rel.to
try:
return model.objects.get(name='All')
except ObjectDoesNotExist:

View File

@ -626,10 +626,11 @@ if django.VERSION < (1, 8, 0):
def get_fk_model(model, fieldname):
'''returns None if not foreignkey, otherswise the relevant model'''
try:
field_object, model, direct, m2m = model._meta.get_field_by_name(fieldname)
field_object = model._meta.get_field(fieldname)
direct = not field_object.auto_created or field_object.concrete
except FieldDoesNotExist:
return None
if not m2m and direct and isinstance(field_object, ForeignKey):
if not field_object.m2m and direct and isinstance(field_object, ForeignKey):
return field_object.rel.to
return None
else:

View File

@ -19,10 +19,11 @@ if django.VERSION < (1, 8, 0):
def get_fk_model(model, fieldname):
'''returns None if not foreignkey, otherswise the relevant model'''
try:
field_object, model, direct, m2m = model._meta.get_field_by_name(fieldname)
field_object = model._meta.get_field(fieldname)
direct = not field_object.auto_created or field_object.concrete
except FieldDoesNotExist:
return None
if not m2m and direct and isinstance(field_object, ForeignKey):
if not field_object.m2m and direct and isinstance(field_object, ForeignKey):
return field_object.rel.to
return None
else: