Django ModelAdmin 中设置字段的默认值

参考:
http://stackoverflow.com/questions/10000950/how-to-set-initial-data-for-django-admin-model-add-instance-form

覆盖formfield_for_dbfield方法
class MAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        field =  super(MAdmin, self).formfield_for_dbfield(db_field, **kwargs)
        if db_field.name == 'description':
            field.initial = 'My initial description'
        return field

你可能感兴趣的:(Django)