Python django admin 替换表单控件

时间:2021-10-08 05:02:37

测试版本:

Python 2.7 Django 1.6.2  

models.py

from django.db import models

class Article(models.Model):
title = models.CharField(u'文章标题', max_length=120, blank=True)
summary = models.CharField(u'文章摘要', max_length=255, blank=True)

admin.py

from django.contrib import admin
from django.forms import forms, models class ArticleAdminForm(models.ModelForm):
class Meta:
model = Article
widgets = {
'summary': forms.Textarea(), # 修改表单控件为文本域
} class ArticleAdmin(admin.ModelAdmin):
form = ArticleAdminForm
list_display = ['id', 'title', 'summary]
#...

原文地址:

http://www.cnblogs.com/zhangbo127/p/4613556.html

参考地址:

http://timonweb.com/snippets/override-field-widget-in-django-admin-form/