Skip to content

Commit 0a6773e

Browse files
authored
Update views.py
1 parent 405670f commit 0a6773e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

advanced_filters/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def get(self, request, model=None, field_name=None):
6161
models.TimeField)):
6262
logger.debug('No choices calculated for field %s of type %s',
6363
field, type(field))
64+
if isinstance(field, models.ForeignKey):
65+
related_model = field.related_model
66+
related_objects = related_model.objects.all()
67+
max_choices = getattr(settings, 'ADVANCED_FILTERS_MAX_CHOICES', 254)
68+
69+
if related_objects.count() <= max_choices:
70+
choices = [(obj.pk, str(obj)) for obj in related_objects]
71+
else:
72+
choices = []
6473
else:
6574
# the order_by() avoids ambiguity with values() and distinct()
6675
choices = model_obj.objects.order_by(field.name).values_list(

0 commit comments

Comments
 (0)