Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed list filter threshold to 25

  • Loading branch information...
commit 21ef5fc61a6f5d55b33be398860afd8b4aa47c6c 1 parent 7fcdc0c
Rick van Hattem authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 django_utils/management/commands/admin_autogen.py
16 django_utils/management/commands/admin_autogen.py
View
@@ -25,6 +25,8 @@
'slug': ('name',)
}
+LIST_FILTER_TRESHOLD = 25
+RAW_ID_THRESHOLD = 100
class Command(BaseCommand):
@@ -85,11 +87,17 @@ def handle_app(self, app, **options):
if isinstance(field, LIST_FILTER):
if isinstance(field, models.ForeignKey):
- if(field.related.parent_model.objects.all()[:100]
- .count() <= 100):
- model_dict['list_filter'].append(field.name)
- else:
+ related_count = (field.related.parent_model.objects
+ .all()
+ [:max(LIST_FILTER_TRESHOLD, RAW_ID_THRESHOLD)]
+ .count()
+ )
+
+ if related_count >= RAW_ID_THRESHOLD:
model_dict['raw_id_fields'].append(field.name)
+
+ if related_count >= LIST_FILTER_TRESHOLD:
+ model_dict['list_filter'].append(field.name)
else:
model_dict['list_filter'].append(field.name)
Please sign in to comment.
Something went wrong with that request. Please try again.