Skip to content
Browse files

Fix maximum recursion error when looking up self-referential FKs, fixes

  • Loading branch information...
1 parent e2ab43d commit 1f973a981847bc0e24db4acb38278592594a4756 @coleifer committed Mar 26, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 flask_peewee/admin.py
View
8 flask_peewee/admin.py
@@ -164,9 +164,10 @@ def get_display_name(self):
def get_admin_name(self):
return slugify(self.model.__name__)
- def get_lookups(self, prefix=''):
+ def get_lookups(self, prefix='', seen=None):
field_value_map = FieldValueMap(self)
+ seen = seen or set()
lookups = {}
active_lookups = []
@@ -186,8 +187,9 @@ def get_lookups(self, prefix=''):
if isinstance(field, ForeignKeyField):
rel_prefix = '%s%s__' % (prefix, field.name)
rel_model = field.to
- if rel_model in self.admin:
- rel_lookups, rel_active = self.admin[rel_model].get_lookups(rel_prefix)
+ if rel_model in self.admin and rel_model not in seen:
+ seen.add(rel_model)
+ rel_lookups, rel_active = self.admin[rel_model].get_lookups(rel_prefix, seen)
lookups.update(rel_lookups)
active_lookups.extend(rel_active)

0 comments on commit 1f973a9

Please sign in to comment.
Something went wrong with that request. Please try again.