python models.py抛出错误

时间:2013-05-02 12:53:52

标签: python django

我刚刚更新了我的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并且发生了错误,但为什么?

1 个答案:

答案 0 :(得分:10)

您的班级couponVotes不会继承models.Model