0

这是我的模型:

class BaseModelTalk(models.Model):

    name            = models.CharField('Name', max_length = 100)
    slug            = models.SlugField('Slug', blank = True)
    creator         = models.ForeignKey('person.Person')
    date_created    = models.DateTimeField(default = now)
    objects         = CustomTalkManager()

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        if not self.id:
            self.slug = slugify(self.name)
        super(BaseModelTalk, self).save(*args, **kwargs)

    def __unicode__(self):
        return u'%s' % self.slug

class Talk(BaseModelTalk):

    tags            = TaggableManager()
    description     = models.TextField('Talk description')

    class Meta:
        verbose_name = 'Talk'
        verbose_name_plural = 'Talks'

class ThreadTextRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadText')

class ThreadImageRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadImage')

class ThreadLinkRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadLink')

class Thread(BaseModelTalk):

    THREAD_TYPE = (('text', 'Text'),
                   ('image', 'Image'),
                   ('link', 'Link'))

    type            = models.CharField('Thread\'s type', max_length = 5, choices = THREAD_TYPE, blank = True, null = True)

    class Meta:
        abstract = True

class ThreadText(Thread):

    ratings         = Ratings(ThreadTextRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'text_threads')
    content         = models.TextField('Thread\'s context')

    class Meta:
        verbose_name = 'Text'
        verbose_name_plural = 'Text\'s'  

class ThreadImage(Thread):

    ratings         = Ratings(ThreadImageRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'image_threads')
    image           = ImageField('Thread\'s image', upload_to = 'thread/image/')

    class Meta:
        verbose_name = 'Image'
        verbose_name_plural = 'Image\'s'

class ThreadLink(Thread):

    ratings         = Ratings(ThreadLinkRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'link_threads')
    link            = models.URLField('Thread\'s link')

    class Meta:
        verbose_name = 'Link'
        verbose_name_plural = 'Link\'s'

每次我运行syncdb时,我都会收到一个错误:django.db.utils.DatabaseError: no such table: talk_basemodeltalk

我已经将应用程序放在我的settings.py哪个是talk.

我真的不知道是什么原因造成的,唯一的线索是如果我class Meta评论BaseModelTalk那行,我没有错误。

4

1 回答 1

1

错误原因:我们不能子类化一个模型,在那里我们明确定义一个管理器,自定义或非自定义。只需将objects线从其中移除BaseModelTalk并将其放置在abstract = False将要修复它的每个模型上。

于 2012-12-18T09:50:41.900 回答