UPDATE:
By now with the code below, I do get a list of the letters in the alphabet, and when clicking on one of those, the place names starting with that letter do appear, and are correctly clickable. But I still get the error about the Column aliases when I click on 'show counts'...
class PlaceFilter(admin.SimpleListFilter):
title = 'first letter of place name'
parameter_name = 'letter'
def lookups(self, request, model_admin):
qs = model_admin.get_queryset(request)
letters = list(string.ascii_uppercase)
options = [(letter, letter) for letter in letters]
if val := self.value():
print(val)
if len(val) == 1:
sub_options = list(qs.values_list('place__name', 'place__name').distinct() \
.filter(place__name__iregex=rf"^('s-|'s )?{val}") \
.order_by('place__name'))
val_index = options.index((val, val))
index = val_index + 1
for option in sub_options:
options.insert(index, option)
index += 1
return list(options)
def queryset(self, request, queryset):
if self.value() and len(self.value()) > 1:
return queryset.filter(place__name=self.value())