Trying to follow these directions in documentation: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides
Getting this error msg: 'module' object has no attribute 'TextField'
What am I missing?This code in models.py
class MyTest(models.Model):
mydesc = models.TextField(_('my desc'), )
This code in admin.py (noting relevant imports)
from django.contrib import admin
from django.db import models
from django.forms import Textarea
from myproject.myapp import MyTest
class MySizedTextarea(forms.Textarea):
开发者_JS百科 def __init__(self, *args, **kwargs):
attrs = kwargs.setdefault('attrs', {})
attrs.setdefault('cols', 80)
attrs.setdefault('rows', 1)
super(MySizedTextarea, self).__init__(*args, **kwargs)
class MyTestAdmin(admin.ModelAdmin):
fields = ('mydesc', )
formfield_overrides = { models.TextField: {'widget': MySizedTextarea}, }
Try specifying the namespace for models more explicitly (for example, if using the GIS models):
import django.contrib.gis.db.models
class MyAdmin(admin.ModelAdmin):
formfield_overrides = { django.contrib.gis.db.models.TextField: {'widget': forms.TextInput(attrs={'size':20})},}
精彩评论