我正在为博客应用程序构建一个模型。
这是模型:
from django.db import models
class Tag(models.Model):
keyword = models.CharField(max_length=256)
posts = models.ManyToManyField(Post)
def __unicode__(self):
return self.keyword
class Post(models.Model):
title = models.CharField(max_length=512)
image = models.ImageField
body = models.TextField()
visible = models.BooleanField()
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
tags = models.ManyToManyField(Tag)
def __unicode__(self):
return self.title
我将博客包添加到settings.py。然后我跑了python manage.py sql blog
。我收到以下错误:
File "/pathto/blog/models.py", line 5, in Tag
posts = models.ManyToManyField(Post)
NameError: name 'Post' is not defined
我不明白为什么没有定义 Post,因为我在 models.py 文件中定义了它。我错过了什么?