我在forms.py
中有一个表单class EmailForm(forms.Form):
recipient = forms.CharField(max_length=14, min_length=12,
widget=forms.TextInput(attrs=require))
message = forms.CharField(max_length=140, min_length=1,
widget=forms.Textarea(attrs={'cols': 30, 'rows': 5}))
我的网站网址是
admin.autodiscover()
urlpatterns = patterns('', (r'^admin/(.*)',
include(admin.site.urls)),)
现在我希望它显示在管理界面
上到目前为止我试过了
首次尝试
from myapps.forms import EmailForm
class EmailAdmin(admin.ModelAdmin):
form = EmailForm
did not work Exception Value:
'DeclarativeFieldsMetaclass' object is not iterable
第二次尝试 现在我跟着http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri ... 但无法得到帮助
class EmailAdmin(admin.ModelAdmin):
def my_view(self,request):
return admin_my_view(request,self)
def get_urls(self):
urls = super(SmsAdmin, self).get_urls()
my_urls = patterns('',(r'^my_view/
$',self.admin_site.admin_view(self.my_view)))
return my_urls + urls
def admin_my_view(request, model_admin):
opts = model_admin.model._meta
admin_site = model_admin.admin_site
has_perm = request.user.has_perm(opts.app_label \
+ '.' + opts.get_change_permission())
context = {'admin_site': admin_site.name,
'title': "My Custom View",
'opts': opts,
'root_path': '/%s' % admin_site.root_path,
'app_label': opts.app_label,
'has_change_permission': has_perm}
template = 'admin/demo_app/admin_my_view.html'
return render_to_response(template,
context,context_instance=RequestContext(request))
admin.site.register(EmailForm,EmailAdmin)
当我运行服务器并在浏览器localhost:8000 / admin上输入 然后按Enter键
Exception Value:
'DeclarativeFieldsMetaclass' object is not iterable
第二次在我第一次进入后再次进入它显示 我是管理页面,但我在管理界面中看不到我的EmailAdmin ..
请帮助我或建议我任何链接。
由于
答案 0 :(得分:0)
(这是我尝试重新格式化您的模型代码):
class EmailForm(forms.Form):
recipient = forms.CharField(max_length=14, min_length=12,
widget=forms.TextInput(attrs=require))
message = forms.CharField(max_length=140, min_length=1,
widget=forms.Textarea(attrs={'cols': 30, 'rows': 5}))
我会把钱放在说“attrs=require
”的位上 - 如果这不是拼写错误。
你想要的是这样的东西:
recipient = forms.CharField(max_length=14, min_length=12,
widget=forms.TextInput(), required=True)