Skip to content

Commit

Permalink
Removed dep method get_all_field_name method from Django 1.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuhaib M Siddique committed Jul 26, 2016
1 parent d3c9ebe commit 65b68d5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion social/apps/django_app/default/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ def get_search_fields(self, request=None):
hasattr(_User, 'username') and 'username' or \
None
fieldnames = ('first_name', 'last_name', 'email', username)
all_names = _User._meta.get_all_field_names()
all_names = self._get_all_field_names(_User._meta)
search_fields = [name for name in fieldnames
if name and name in all_names]
return ['user__' + name for name in search_fields]

@staticmethod
def _get_all_field_names(model):
from itertools import chain

return list(set(chain.from_iterable(
(field.name, field.attname) if hasattr(field, 'attname') else (field.name,)
for field in model.get_fields()
# For complete backwards compatibility, you may want to exclude
# GenericForeignKey from the results.
if not (field.many_to_one and field.related_model is None)
)))


class NonceOption(admin.ModelAdmin):
"""Nonce options"""
Expand Down

0 comments on commit 65b68d5

Please sign in to comment.