2014-03-06 69 views
0

我正在嘗試在我的UserProfile類的管理界面中添加搜索字段。Django,嘗試在管理界面中添加搜索字段時出錯

這是我models.py

class UserProfile(models.Model): 
    user = models.ForeignKey(User, default=None, null=True, 
          related_name='profile') # don't judge me. I had to use null=True 
    registered = models.BooleanField(default=False) 
    activated = models.BooleanField(default=False) 
    activation_key = models.CharField(max_length=128) 
    receive_notifications = models.BooleanField(default=False) 
    email = models.CharField(max_length=80, default='') 

    def __unicode__(self): 
     return self.email 

這是我admin.py

from main.models import UserProfile 
from django.contrib import admin 

class UserProfileAdmin(admin.ModelAdmin): 
    search_fields = ['email'] 

admin.site.register(UserProfileAdmin) 

當我嘗試運行服務器我得到這個錯誤:

'MediaDefiningClass' object is not iterable在該行地方我註冊UserProfileAdmin

我在做什麼錯?

回答

2

admin.site.register(UserProfileAdmin) 

應該

admin.site.register(UserProfile, UserProfileAdmin) 
+0

哎喲!謝謝:-) – xpanta

+0

:)你的歡迎;) –