Django - 自定義表字段的 help_text 文本內容


class GoodsForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(GoodsForm, self).__init__(*args, **kwargs)
        goods_obj = Goods.objects.order_by('-paixu').first()
        if goods_obj:
            self.fields['paixu'].help_text = "越大越靠前, 當前商品排序最大值為: %s" % goods_obj.paixu
        self.fields['is_show'].help_text = format_html('<p style="color: red;">請注意該選項 !</p>')

    class Meta:
        model = Goods
        exclude = ()


@admin.register(Goods)
class DianPuAdmin(admin.ModelAdmin):
    list_display = ["id", "mingcheng", "paixu", "create_time"]
    form = GoodsForm

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM