开发者

Django-Admin Exception Value: 'DeclarativeFieldsMetaclass' object is not iterable

I have one form in 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}))

and my site url is

admin.autodiscover()
urlpatterns = patterns('',  (r'^admin/(.*)',
include(admin.site.urls)),)

now I want it to be shown on admin interface

I tried so far

First attempt

from myapps.forms import EmailForm
class EmailAdmin(admin.ModelAdmin):
     form = EmailForm
did not work Exception Value:
'DeclarativeFieldsMetaclass' object is not iterable

Second attempt and now I followed http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri... but could not get help

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开发者_开发问答)

and when I run server and type on browser localhost:8000/admin and hit enter button

Exception Value:
'DeclarativeFieldsMetaclass' object is not iterable

and second time just after first time when I again enter then it show me the admin page but I can't see my EmailAdmin in admin interface..

Just help me or suggest me any link.

Thanks


(This is my attempt at reformatting your model code):

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}))

I would put my money on the bit that says "attrs=require" -- if that's not a typo.

What you want instead is something like this:

    recipient = forms.CharField(max_length=14, min_length=12,
         widget=forms.TextInput(), required=True)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜