Usage of the documented API for models _meta
This commit is contained in:
parent
d0e92ed8f7
commit
29522aad4e
@ -369,8 +369,16 @@ class DjangoAuthUser(AuthUser): # pragma: no cover
|
|||||||
"""
|
"""
|
||||||
if self.user:
|
if self.user:
|
||||||
attr = {}
|
attr = {}
|
||||||
for field in self.user._meta.fields:
|
# _meta.get_fields() is from the new documented _meta interface in django 1.8
|
||||||
attr[field.attname] = getattr(self.user, field.attname)
|
try:
|
||||||
|
field_names = [
|
||||||
|
field.attname for field in self.user._meta.get_fields() if hasattr(field, "attname")
|
||||||
|
]
|
||||||
|
# backward compatibility with django 1.7
|
||||||
|
except AttributeError: # pragma: no cover (only used by django 1.7)
|
||||||
|
field_names = self.user._meta.get_all_field_names()
|
||||||
|
for name in field_names:
|
||||||
|
attr[name] = getattr(self.user, name)
|
||||||
return attr
|
return attr
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
Loading…
Reference in New Issue
Block a user