Skip to content

Commit

Permalink
Add merge author action to author admin
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Jun 11, 2024
1 parent a7ef76c commit ab63623
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion fragdenstaat_de/fds_blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
from froide.helper.widgets import TagAutocompleteWidget

from .documents import index_article
from .models import Article, ArticleTag, Author, Category, Publication, TaggedArticle
from .models import (
Article,
ArticleAuthorship,
ArticleTag,
Author,
Category,
LatestArticlesPlugin,
Publication,
TaggedArticle,
)


class RelatedPublishedFilter(admin.SimpleListFilter):
Expand Down Expand Up @@ -97,6 +106,19 @@ class CategoryListFilter(RelatedPublishedFilter):

class AuthorAdmin(admin.ModelAdmin):
raw_id_fields = ("user",)
actions = ["merge_authors"]

def merge_authors(self, request, queryset):
assert len(queryset) >= 1
author = queryset[0]
other_authors = list(queryset)[1:]
for other in other_authors:
ArticleAuthorship.objects.filter(author=other).update(author=author)
plugins = LatestArticlesPlugin.objects.filter(authors=other)
for plugin in plugins:
plugin.authors.remove(other)
plugin.authors.add(author)
other.delete()


class AuthorshipInlineAdmin(SortableInlineAdminMixin, admin.TabularInline):
Expand Down

0 comments on commit ab63623

Please sign in to comment.