无法导入名称'发布'

时间:2017-11-15 09:19:29

标签: python django import

我无法在我的django模型中导入类Post,当我尝试runserver时,它返回importError:无法导入名称“Post”,我已经在这几天了,请帮帮我..谢谢< / p>

这是我的Post

类模型
from .models import Post,  Comment

class Post(models.Model):
     objects = models.Manager() 
     published = PublishedManager()

     def get_absolute_url(self):
         return reverse('blog:post_detail',args=[self.publish.year,self.publish.strftime('%m'), self.publish.strftime('%d'),self.slug])

    STATUS_CHOICES = (('draft', 'Draft'),('published', 'Published'),)
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250, 
    unique_for_date='publish')
    author = models.ForeignKey(User,
    related_name='blog_posts')
    body = models.TextField()
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10, 
    choices=STATUS_CHOICES,default='draft')
class Meta:
     ordering = ('-publish',)
     def __unicode__(self):
         return self.title

这也是我的评论类模型

from .models import Post,  Comment

class Comment(models.Model):
    post = models.ForeignKey(Post, related_name='comments')
    name = models.CharField(max_length=80)
    email = models.EmailField()
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    active = models.BooleanField(default=True)
class Meta:
    ordering = ('created',)
    def __unicode__(self):
     return 'Comment by {} on {}'.format(self.name, self.post)

1 个答案:

答案 0 :(得分:2)

为什么要尝试将Post和Comment模型导入到定义它们的同一文件中?没有理由这样做;删除那些导入行。