Django By Example 中问题求助


post = get_object_or_404(Post, slug=post,
    status='published',
    publish__year=year,
    publish__month=month,
    publish__day=day)

报错:报django.core.exceptions.FieldError: Cannot resolve keyword 'publish_year' into field 这种错误 有遇到的吗? 不理解作者为什么要写publish_year,models中只有publish,我自己感觉这样是不对的,但是作者好像没问题.

class Post(models.Model):
    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 __str__(self):
        return self.title
添加一条新回复
登录 或者 注册 后发表回复