<commit_before># -*- coding: utf-8 -*-
from django.contrib import admin

from blogging.models import Category, Post
from blogging.actions import make_published, make_draft

# Attachements management
try:
    from attachements.admin import AttachementInline
    post_inlines = [AttachementInline,]
except ImportError:
    post_inlines = []

# Model admin
class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
    list_display = ('name','site')
    list_filter = ('site',)
    search_fields = ('name',)

class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'author', 'status', 'published_on', 'selected', 'site')
    list_filter = ['site', 'author', 'status', 'selected']
    date_hierarchy = 'published_on'
    prepopulated_fields = {"slug": ("title",)}
    search_fields = ('exceprt','content','item__title')
    inlines = post_inlines
    actions = [make_published, make_draft]

    def formfield_for_manytomany(self, db_field, request, **kwargs):
        """
        Monkey patching the form field for categories
        TODO: Create a widget to manage it more easily
        """
        field = super(PostAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
        field.queryset = field.queryset.order_by('site__domain')<commit_msg>* Improved blogging admin (added filtering by category)<commit_after># -*- coding: utf-8 -*-
from django.contrib import admin

from blogging.models import Category, Post
from blogging.actions import make_published, make_draft

# Attachements management
try:
    from attachements.admin import AttachementInline
    post_inlines = [AttachementInline,]
except ImportError:
    post_inlines = []

# Model admin
class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
    list_display = ('name','site')
    list_filter = ('site',)
    search_fields = ('name',)

class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'author', 'status', 'published_on', 'selected', 'site')
    list_filter = ['site', 'author', 'status', 'selected', 'categories']
    date_hierarchy = 'published_on'
    prepopulated_fields = {"slug": ("title",)}
    search_fields = ('exceprt','content','item__title')
    inlines = post_inlines
    actions = [make_published, make_draft]

    def formfield_for_manytomany(self, db_field, request, **kwargs):
        """
        Monkey patching the form field for categories
        TODO: Create a widget to manage it more easily
        """
        field = super(PostAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
        field.queryset = field.queryset.order_by('site__domain')
{'fraction_non_alphanumeric': 0.1279333838001514, 'fraction_numerical': 0.000757002271006813, 'mean_word_length': 4.296593186372745, 'pattern_counts': {'":': 4, '<': 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': '2048537', 'n_tokens_mistral': 784, 'n_tokens_neox': 784, 'n_words': 199}