Reputation: 1
i can't import a class Post in my django models,when i try to runserver, its returns importError:cannot import name "Post",i have been on this for some days now,please help me..thanks
this is my class models for 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
And this also my class model for Comment
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)
Upvotes: 0
Views: 61
Reputation: 599788
Why are you trying to import the Post and Comment models into the same file where they are defined? There is no reason to do that; delete those import lines.
Upvotes: 2