Skip to content

Commit

Permalink
Add article admin action to add category to article
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Jun 11, 2024
1 parent e0f2c12 commit 0223b59
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions fragdenstaat_de/fds_blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0223b59

Please sign in to comment.