# HG changeset patch # User neko259 # Date 2016-05-10 08:36:16 # Node ID c6fc710a8ae2df5e9cc00a079d50129ed8a0e253 # Parent fe8b0767de0c0ef5e30eb9b2bd28d91df52227de Show global id as a link in admin site diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -7,12 +7,12 @@ from boards.models import Post, Tag, Ban @admin.register(Post) class PostAdmin(admin.ModelAdmin): - list_display = ('id', 'title', 'text', 'poster_ip', 'linked_images') + list_display = ('id', 'title', 'text', 'poster_ip', 'linked_images', 'linked_global_id') list_filter = ('pub_time',) search_fields = ('id', 'title', 'text', 'poster_ip') - exclude = ('referenced_posts', 'refmap', 'images') + exclude = ('referenced_posts', 'refmap', 'images', 'global_id') readonly_fields = ('poster_ip', 'threads', 'thread', 'linked_images', - 'attachments', 'uid', 'url', 'pub_time', 'opening') + 'attachments', 'uid', 'url', 'pub_time', 'opening', 'linked_global_id') def ban_poster(self, request, queryset): bans = 0 @@ -45,6 +45,14 @@ class PostAdmin(admin.ModelAdmin): return ', '.join(image_urls) linked_images.allow_tags = True + def linked_global_id(self, obj: Post): + global_id = obj.global_id + if global_id is not None: + return '{}'.format( + reverse('admin:%s_%s_change' % (global_id._meta.app_label, + global_id._meta.model_name), + args=[global_id.id]), str(global_id)) + linked_global_id.allow_tags = True actions = ['ban_poster', 'ban_with_hiding'] @@ -125,4 +133,4 @@ class GlobalIdAdmin(admin.ModelAdmin): return Post.objects.filter(global_id=obj).exists() list_display = ('__str__', 'is_linked',) - readonly_fields = ('content',) \ No newline at end of file + readonly_fields = ('content',)