def queryset(self, request, queryset): all_count = queryset.count() translated_count = queryset.exclude(translation='').count() untranslated_count = all_count - translated_count translated_title = u'{translated_label} ({translated_count} / {all_count})'.format( translated_label=self.lookup_choices[0][1], translated_count=translated_count, all_count=all_count, ) untranslated_title = u'{translated_label} ({untranslated_count} / {all_count})'.format( translated_label=self.lookup_choices[1][1], untranslated_count=untranslated_count, all_count=all_count, ) self.lookup_choices = [ (choices.TRANSLATIONS_TRANSLATED, cf(translated_title)), (choices.TRANSLATIONS_UNTRANSLATED, cf(untranslated_title)), ] if self.value() == choices.TRANSLATIONS_TRANSLATED: return queryset.exclude(translation="") if self.value() == choices.TRANSLATIONS_UNTRANSLATED: return queryset.filter(translation="")
def lookups(self, request, model_admin): return [(i, cf(_(label))) for i, (group_filter, label) in enumerate(get_settings('TRANSLATIONS_CUSTOM_FILTERS'))]
def __init__(self, *args, **kwargs): self.title = cf(_(get_settings('TRANSLATIONS_CUSTOM_FILTERS_LABEL'))) super(CustomFilter, self).__init__(*args, **kwargs)