<commit_before>from django.contrib import admin
from django.db import models
from django.contrib.auth.models import User

from pagedown.widgets import AdminPagedownWidget

from .models import Place, Award, MetaAward, MetaEvent, Diffusion


class AwardAdmin(admin.ModelAdmin):
    list_display = ('get_year', 'get_award', 'get_artwork')
    search_fields = ['meta_award__label', 'artwork__title', 'artwork__authors__user__last_name']
    ordering = ['date']
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }

    def get_year(self, obj):
        return obj.date.year
    get_year.short_description = "Annee"
    get_year.admin_order_field = 'date'

    def get_award(self, obj):
        return obj.meta_award.label
    get_award.short_description = "Titre"
    get_award.admin_order_field = 'meta_award__label'

    def get_artwork(self, obj):
        return ", ".join([artwork.__str__() for artwork in obj.artwork.all()])
    get_artwork.short_description = "Oeuvre(s)"
    get_artwork.admin_order_field = 'artwork'

    # order manytomany artist field
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "artist":
            kwargs["queryset"] = User.objects.order_by('first_name')
        return super(admin.ModelAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)


class PlaceAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }


class MetaEventAdmin(admin.ModelAdmin):
    list_display = ('event', 'genres', 'keywords_list', 'get_periode')
    search_fields = ['event__title', 'event__starting_date']
    ordering = ['event', ]

    def keywords_list(self, obj):
        return u", ".join(o.name for o in obj.keywords.all())

    def get_periode(self, obj):
        return obj.event.starting_date.strftime("%B")
    get_periode.short_description = 'Periode'


class MetaAwardAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }


class DiffusionAdmin(admin.ModelAdmin):
    list_display = ('artwork', 'event', 'first', 'on_competition')
    ordering = ['artwork', ]


admin.site.register(Place, PlaceAdmin)
admin.site.register(Award, AwardAdmin)
admin.site.register(MetaAward, MetaAwardAdmin)
admin.site.register(MetaEvent, MetaEventAdmin)
admin.site.register(Diffusion, DiffusionAdmin)<commit_msg>Update Diffusion admin : search field<commit_after>from django.contrib import admin
from django.db import models
from django.contrib.auth.models import User

from pagedown.widgets import AdminPagedownWidget

from .models import Place, Award, MetaAward, MetaEvent, Diffusion


class AwardAdmin(admin.ModelAdmin):
    list_display = ('get_year', 'get_award', 'get_artwork')
    search_fields = ['meta_award__label', 'artwork__title', 'artwork__authors__user__last_name']
    ordering = ['date']
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }

    def get_year(self, obj):
        return obj.date.year
    get_year.short_description = "Annee"
    get_year.admin_order_field = 'date'

    def get_award(self, obj):
        return obj.meta_award.label
    get_award.short_description = "Titre"
    get_award.admin_order_field = 'meta_award__label'

    def get_artwork(self, obj):
        return ", ".join([artwork.__str__() for artwork in obj.artwork.all()])
    get_artwork.short_description = "Oeuvre(s)"
    get_artwork.admin_order_field = 'artwork'

    # order manytomany artist field
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "artist":
            kwargs["queryset"] = User.objects.order_by('first_name')
        return super(admin.ModelAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)


class PlaceAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }


class MetaEventAdmin(admin.ModelAdmin):
    list_display = ('event', 'genres', 'keywords_list', 'get_periode')
    search_fields = ['event__title', 'event__starting_date']
    ordering = ['event', ]

    def keywords_list(self, obj):
        return u", ".join(o.name for o in obj.keywords.all())

    def get_periode(self, obj):
        return obj.event.starting_date.strftime("%B")
    get_periode.short_description = 'Periode'


class MetaAwardAdmin(admin.ModelAdmin):
    search_fields = ('label', 'event__title',)

    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }


class DiffusionAdmin(admin.ModelAdmin):
    list_display = ('artwork', 'event', 'first', 'on_competition')
    ordering = ['artwork', ]


admin.site.register(Place, PlaceAdmin)
admin.site.register(Award, AwardAdmin)
admin.site.register(MetaAward, MetaAwardAdmin)
admin.site.register(MetaEvent, MetaEventAdmin)
admin.site.register(Diffusion, DiffusionAdmin)
{'fraction_non_alphanumeric': 0.1200485044462409, 'fraction_numerical': 0.0, 'mean_word_length': 4.35027027027027, 'pattern_counts': {'":': 2, '<': 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': '2835913', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1566, 'n_words': 306}