我正在看《 Django 2示例》一书。但是,被困在这里。 我尝试通过互联网进行搜索,但没有得到任何具体信息。
models.py >>
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
# Create your models here.
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset()\
.filter(status='published')
class post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=126)
slug = models.SlugField(max_length=126, unique_for_date='publish')
author = models.ForeignKey(User, related_name='blog_post', on_delete=models.CASCADE)
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')
objects = models.Manager() #default manager
published = PublishedManager() #custom manager
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blogposts:post_detail',
args=[
self.publish.year,
self.publish.strftime('%m'),
self.publish.strftime('%d'),
self.slug ])
This教程正在做同样的事情。但是我从pylint收到一个错误,E1101: Instance of 'DateTimeField' has no 'strftime' member
我想念什么?