Django管理站点获取要在html中显示的id
我只是想,如果管理员选择学生,它将获得id并显示在html模板中 管理员Django管理站点获取要在html中显示的id,django,Django,我只是想,如果管理员选择学生,它将获得id并显示在html模板中 管理员 @admin.register(studentDiscount) class studentDiscount(admin.ModelAdmin): list_display = ('Students_Enrollment_Records', 'Discount_Type','my_url_field') ordering = ('Students_Enrollment_Records',) sear
@admin.register(studentDiscount)
class studentDiscount(admin.ModelAdmin):
list_display = ('Students_Enrollment_Records', 'Discount_Type','my_url_field')
ordering = ('Students_Enrollment_Records',)
search_fields = ('Students_Enrollment_Records',)
def my_url_field(self, obj):
return format_html("<a href='https://www.school.ph/enrollmentform/?StudentID=pk'>Report</a>", obj.Discount_Type)
my_url_field.allow_tags = False
my_url_field.short_description = 'Report'
如果要在URL中使用
折扣\u Type.pk
,请使用如下格式:
返回格式\u html(“https://www.school.ph/enrollmentform/?StudentID={}报告”,对象折扣_Type.pk)
class studentDiscount(models.Model):
Students_Enrollment_Records = models.ForeignKey(StudentsEnrollmentRecord, related_name='+',
on_delete=models.CASCADE, null=True)
Discount_Type = models.ForeignKey(Discount, related_name='+', on_delete=models.CASCADE, null=True,blank=True)
return format_html("https://www.school.ph/enrollmentform/?StudentID={}'>Report", obj.Discount_Type.pk)