Skip to content

admin

django_spire.comment.admin

CommentAdmin

Bases: ModelAdmin

list_display = ('id', 'user_link', 'content_object_link', 'information_snippet', 'created_datetime', 'is_edited') class-attribute instance-attribute

list_filter = ('created_datetime', 'is_edited') class-attribute instance-attribute

search_fields = ('id', 'user__username', 'information') class-attribute instance-attribute

ordering = ('-created_datetime',) class-attribute instance-attribute

Source code in django_spire/comment/admin.py
def user_link(self, comment: models.Comment) -> str:
    url = reverse('admin:auth_user_change', args=[comment.user.id])
    return format_html(f'<a href="{url}">{comment.user.username}</a>')
Source code in django_spire/comment/admin.py
def content_object_link(self, comment: models.Comment) -> str:
    url = (
        reverse(
            f'admin:{comment.content_type.app_label}_{comment.content_type.model}_change',
            args=[comment.object_id]
        )
    )

    return format_html(f'<a href="{url}">{comment.content_object}</a>')

information_snippet

Source code in django_spire/comment/admin.py
def information_snippet(self, comment: models.Comment) -> str:
    return (
        comment.information[:20] + '...'
        if len(comment.information) > 20
        else comment.information
    )