2013-05-02 81 views
0

我剛剛更新了我的models.py,現在我收到錯誤.. 這是拋出的錯誤:蟒蛇models.py投擲的錯誤

驗證模型...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x9eb5dec>> 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 91, in inner_run 
    self.validate(display_num_errors=True) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate 
    num_errors = get_validation_errors(s, app) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors 
    for (app_name, error) in get_app_errors().items(): 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 158, in get_app_errors 
    self._populate() 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate 
    self.load_app(app_name, True) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 88, in load_app 
    models = import_module('.models', app_name) 
    File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
    File "/home/vaibhav/TRAC/bright-coupons/brightCoupons/brightCouponsApp/models.py", line 75, in <module> 
    admin.site.register(couponVotes, couponVotesAdmin) 
    File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py", line 74, in register 
    for model in model_or_iterable: 
TypeError: 'classobj' object is not iterable 

每當我試着要運行python manage.py runserver命令

這是我的models.py:

from django.db import models 
from django.contrib import admin 

#------------------------------------------------------------------------------ 

class store(models.Model): 

    storeName = models.CharField(max_length=30)   # Store Name 


class coupon(models.Model):  

    couponDescription = models.TextField()    # Coupon Description 
    active = models.BooleanField(default=True) 
    couponCode = models.CharField(max_length=30) 
    couponStore = models.CharField(max_length=30)  # Store Name 
    featured = models.BooleanField(default=False) 
    couponTitle = models.CharField(max_length=100)  # Coupon Title 
    updatedAt = models.DateTimeField(auto_now=True) 
    createdAt = models.DateTimeField(auto_now=True) 
    lastTested = models.DateField(auto_now_add=True)  # When was the coupon last tested 
    localCouponId = models.CharField(max_length=30,primary_key=True) 


class commentCoupons(models.Model): 
    couponId = models.CharField(max_length=20)      # CouponId form couponRestApiApp 

    class Meta: 
     """Meta class to control display Behavior of the Model name """ 
     verbose_name_plural = "commentCoupons" 

    def __unicode__(self): 
     """Method to display string correctly""" 
     return unicode(self.couponId) 


class couponVotes(): 
    success = models.IntegerField()      # Count of the number of times people have made it work 
    failure = models.IntegerField()      # Count of the number of times this has failed  
    couponid = models.OneToOneField(commentCoupons) 

class comments(models.Model): 

    comment = models.TextField() 
    addedOn = models.DateField(auto_now=True) 
    userName = models.CharField(max_length=30) 
    commentCoupon = models.ForeignKey(commentCoupons) 

    class Meta: 
     """Meta class to control display Behavior of the Model name """ 
     verbose_name_plural = "comments" 

    def __unicode__(self): 
     """Method to display string correctly""" 
     return unicode(self.comment) 


class commentCouponsAdmin(admin.ModelAdmin): 
    list_display = ('couponId',) 

class commentsAdmin(admin.ModelAdmin): 
    list_display = ('comment','addedOn','userName','commentCoupon',) 

class couponAdmin(admin.ModelAdmin): 
    list_display = ('couponTitle','couponDescription','couponCode', 
        'couponStore','updatedAt', 
        'createdAt','localCouponId','active','featured') 

class couponVotesAdmin(admin.ModelAdmin): 
    list_display = ('success','failure',) 

admin.site.register(coupon,couponAdmin) 
admin.site.register(comments, commentsAdmin) 
admin.site.register(couponVotes, couponVotesAdmin) 
admin.site.register(commentCoupons,commentCouponsAdmin) 

#------------------------------------------------------------------------------ 

我不明白剛剛發生了什麼,我只是增加了新的模型couponVotes和錯誤發生,但爲什麼?

+2

我建議你閱讀http://www.python.org/dev/peps/pep-0008/#class-names以瞭解類命名約定(它不會對你的代碼產生任何問題,但更好地習慣它) – 2013-05-02 12:59:30

+0

我還注意到在定義列表時,代碼中使用了一些額外的逗號。可能想把這些拿出來。 – 2013-05-02 13:01:41

回答

10

您的班級couponVotes未繼承models.Model

+0

是的,我完全忘記了......謝謝.....我的壞... – 2013-05-02 14:28:24