<commit_before>from django.contrib import admin
from bluebottle.votes.models import Vote


class VoteAdmin(admin.ModelAdmin):
    raw_id_fields = ('voter', 'project')

admin.site.register(Vote, VoteAdmin)<commit_msg>Improve project filter<commit_after>from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from bluebottle.common.admin_utils import ImprovedModelForm
from bluebottle.votes.models import Vote


class ProjectFilter(admin.SimpleListFilter):
    title = _('Project')
    parameter_name = 'project'

    def lookups(self, request, model_admin):
        projects = [obj.project for obj in model_admin.model.objects.order_by('project__title').distinct('project__title').all()]
        return [(project.id, project.title) for project in projects]

    def queryset(self, request, queryset):
        if self.value():
            return queryset.filter(project__id__exact=self.value())
        else:
            return queryset


class VoteAdmin(ImprovedModelForm, admin.ModelAdmin):
    raw_id_fields = ('voter', 'project')
    list_display = ('voter', 'project', 'created')
    list_filter = (ProjectFilter, )

admin.site.register(Vote, VoteAdmin)

{'fraction_non_alphanumeric': 0.10570469798657718, 'fraction_numerical': 0.0, 'mean_word_length': 4.472477064220183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5737566', 'n_tokens_mistral': 363, 'n_tokens_neox': 347, 'n_words': 81}