2013-05-02 79 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