这是我的情况:SubCategory
有外键Topic
和Topic
外键SubCategory
。
class SubCategory(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(max_length=110)
description = models.TextField(default='')
ordering = models.PositiveIntegerField(default=1)
category = models.ForeignKey(Category)
created_on = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User)
updated_on = models.DateTimeField(blank=True, null=True)
updated_by = models.ForeignKey(User, related_name='+')
num_topics = models.IntegerField(default=0)
num_posts = models.IntegerField(default=0)
last_topic = models.ForeignKey(Topic, related_name='+')
class Topic(models.Model):
name = models.CharField(max_length=300)
slug = models.SlugField(max_length=300)
description = models.TextField(default='')
subcategory = models.ForeignKey(SubCategory)
created_on = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User)
updated_on = models.DateTimeField(blank=True, null=True)
updated_by = models.ForeignKey(User, related_name='+')
当我运行此代码时,它会给出以下错误:
NameError: name 'Topic' is not defined.
谁能告诉我如何解决它?