Skip to content

Commit 0051132

Browse files
committed
I like sorted() better than in-place .sort()
1 parent cb2e6bd commit 0051132

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

feincms/admin/filters.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ def __init__(self, f, request, params, model, model_admin,
8080
related_model = f.rel.to
8181
related_name = f.related_query_name()
8282

83-
self.lookup_choices = [(
84-
i.pk,
85-
'%s (%s)' % (i, i._related_count),
86-
) for i in related_model.objects.annotate(
87-
_related_count=Count(related_name)
88-
).exclude(_related_count=0)]
89-
self.lookup_choices.sort(key=lambda i: i[1])
83+
self.lookup_choices = sorted(
84+
[
85+
(i.pk, '%s (%s)' % (i, i._related_count))
86+
for i in related_model.objects.annotate(
87+
_related_count=Count(related_name)
88+
).exclude(_related_count=0)
89+
],
90+
key=lambda i: i[1],
91+
)
9092

9193
def choices(self, cl):
9294
yield {

0 commit comments

Comments
 (0)