<commit_before>from django.contrib import admin

from symposion.schedule.models import Schedule, Day, Room, SlotKind, Slot, \
    SlotRoom, Presentation


admin.site.register(Schedule, list_display=("section", "published"))
admin.site.register(Day, list_display=("date", "schedule",))
admin.site.register(Room, list_display=("name", "schedule"))
admin.site.register(SlotKind, list_display=("label", "schedule"))
admin.site.register(Slot, list_display=("day", "start", "end", "kind"))
admin.site.register(SlotRoom, list_display=("slot", "room"))


class PresentationAdmin(admin.ModelAdmin):
    list_display = (
        'number',
        'title',
        'speaker',
        'cancelled',
        'proposal_base',
        'kind',
        'section',
        'tutorial_attendees',
        'tutorial_max'
    )
    list_filter = (
        'section',
        'proposal_base__kind',
        'cancelled',
    )
    search_fields = (
        'title',
        'speaker__name',
        'additional_speakers__name',
        'proposal_base__title',
        'proposal_base__kind__name',
        'description',
        'abstract',
        'section__name',
    )

    def number(self, presentation):
        return presentation.proposal_base.number
    number.admin_order_field = 'proposal_base__pk'

    def kind(self, presentation):
        return presentation.proposal_base.kind

    def tutorial_attendees(self, presentation):
        if hasattr(presentation.proposal, 'registrants'):
            return presentation.proposal.registrants.all().count()
        else:
            return 'N/A'
    tutorial_attendees.short_description = 'Attendees'

    def tutorial_max(self, presentation):
        if hasattr(presentation.proposal, 'max_attendees'):
            return presentation.proposal.max_attendees
        else:
            return 'N/A'
    tutorial_max.short_description = 'Attendees Max'


admin.site.register(Presentation, PresentationAdmin)<commit_msg>simplify admin logic when directly retrieving an attr<commit_after>from django.contrib import admin

from symposion.schedule.models import Schedule, Day, Room, SlotKind, Slot, \
    SlotRoom, Presentation


admin.site.register(Schedule, list_display=("section", "published"))
admin.site.register(Day, list_display=("date", "schedule",))
admin.site.register(Room, list_display=("name", "schedule"))
admin.site.register(SlotKind, list_display=("label", "schedule"))
admin.site.register(Slot, list_display=("day", "start", "end", "kind"))
admin.site.register(SlotRoom, list_display=("slot", "room"))


class PresentationAdmin(admin.ModelAdmin):
    list_display = (
        'number',
        'title',
        'speaker',
        'cancelled',
        'proposal_base',
        'kind',
        'section',
        'tutorial_attendees',
        'tutorial_max'
    )
    list_filter = (
        'section',
        'proposal_base__kind',
        'cancelled',
    )
    search_fields = (
        'title',
        'speaker__name',
        'additional_speakers__name',
        'proposal_base__title',
        'proposal_base__kind__name',
        'description',
        'abstract',
        'section__name',
    )

    def number(self, presentation):
        return presentation.proposal_base.number
    number.admin_order_field = 'proposal_base__pk'

    def kind(self, presentation):
        return presentation.proposal_base.kind

    def tutorial_attendees(self, presentation):
        if hasattr(presentation.proposal, 'registrants'):
            return presentation.proposal.registrants.all().count()
        else:
            return 'N/A'
    tutorial_attendees.short_description = 'Attendees'

    def tutorial_max(self, presentation):
        return getattr(presentation.proposal, 'max_attendees', 'N/A')
    tutorial_max.short_description = 'Attendees Max'


admin.site.register(Presentation, PresentationAdmin)
{'fraction_non_alphanumeric': 0.12324857291126103, 'fraction_numerical': 0.0, 'mean_word_length': 3.226973684210526, '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': '1333333', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1133, 'n_words': 202}