From 0223b5913fb2a4895cc6a85c7a5f99216786f96b Mon Sep 17 00:00:00 2001 From: Stefan Wehrmeyer Date: Tue, 11 Jun 2024 10:33:41 +0200 Subject: [PATCH] Add article admin action to add category to article --- fragdenstaat_de/fds_blog/admin.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fragdenstaat_de/fds_blog/admin.py b/fragdenstaat_de/fds_blog/admin.py index 55fa1fe1f..43558fa8d 100644 --- a/fragdenstaat_de/fds_blog/admin.py +++ b/fragdenstaat_de/fds_blog/admin.py @@ -19,7 +19,7 @@ from djangocms_text_ckeditor.widgets import TextEditorWidget from parler.admin import TranslatableAdmin -from froide.helper.admin_utils import make_nullfilter +from froide.helper.admin_utils import make_choose_object_action, make_nullfilter from froide.helper.widgets import TagAutocompleteWidget from .documents import index_article @@ -104,6 +104,11 @@ class AuthorshipInlineAdmin(SortableInlineAdminMixin, admin.TabularInline): raw_id_fields = ("author",) +def add_category_on_articles(admin, request, queryset, action_obj): + for article in queryset: + article.categories.add(action_obj) + + class ArticleAdminForm(forms.ModelForm): class Meta: model = Article @@ -247,9 +252,12 @@ class ArticleAdmin(SortableAdminBase, admin.ModelAdmin): ) save_on_top = True - actions = ["set_language"] + actions = ["set_language", "add_category"] actions_on_top = True - actions_on_bottom = True + + add_category = make_choose_object_action( + Category, add_category_on_articles, _("Set category on articles...") + ) # def __init__(self, model, admin_site): # # self.form.admin_site = admin_site