<commit_before>from django.contrib import admin

from .models.observers import Observer
from .models.surveys import Survey, SurveyHour

class ObserverAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'email', 'purpose',)

class SurveyHourInline(admin.StackedInline):
    model = SurveyHour
    extra = 0

class SurveyAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'date', 'max_flock_size', 'observer', 'status',)
    list_filter = ('date', 'status',)
    inlines = [SurveyHourInline]
    search_fields = ('id__exact',)

class SurveyHourAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'survey', 'hour', 'kea', 'activity', 'grid_tile',)
    list_filter = ('kea', 'activity',)

admin.site.register(Observer, ObserverAdmin)
admin.site.register(Survey, SurveyAdmin)
admin.site.register(SurveyHour, SurveyHourAdmin)<commit_msg>Survey admin optimisation (#108)<commit_after>from django.contrib import admin

from .models.observers import Observer
from .models.surveys import Survey, SurveyHour

class ObserverAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'email', 'purpose',)

class SurveyHourInline(admin.StackedInline):
    model = SurveyHour
    extra = 0
    list_select_related = True
    raw_id_fields = ('grid_tile',)

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.all(). \
            select_related('survey', 'grid_tile'). \
            all()

class SurveyAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'date', 'max_flock_size', 'observer', 'status',)
    list_filter = ('date', 'status',)
    inlines = [SurveyHourInline]
    search_fields = ('id__exact',)
    list_select_related = True

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.all().select_related('observer').prefetch_related('hours')

class SurveyHourAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'survey', 'hour', 'kea', 'activity', 'grid_tile',)
    list_filter = ('kea', 'activity',)
    list_select_related = True
    raw_id_fields = ('grid_tile',)

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.all().select_related('survey', 'grid_tile',)

admin.site.register(Observer, ObserverAdmin)
admin.site.register(Survey, SurveyAdmin)
admin.site.register(SurveyHour, SurveyHourAdmin)
{'fraction_non_alphanumeric': 0.13994045087196938, 'fraction_numerical': 0.002126754572522331, 'mean_word_length': 4.667469879518072, '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': '618701', 'n_tokens_mistral': 775, 'n_tokens_neox': 755, 'n_words': 153}