具体效果
具体实现
admin.py
from django.utils.html import format_html
@admin.register(models.UsvLicense)
class UsvDataAdmin(admin.ModelAdmin):
def copy_one(self, obj):
return format_html(f"""
<input type="text" id="{obj.id}" value="{obj.uuid}" style="position: absolute; top: -10000px">
<a href="#" onclick="document.getElementById('{obj.id}').select(); document.execCommand('copy'); alert('已复制')">复制授权码</a>
"""
)
copy_one.type = 'success'
copy_one.short_description = '操作'
list_display = ["uuid", "user", "usv_class", "license_date", "copy_one"]