그래서 날짜에서 제거해야합니다. 그래서 날짜, 연도 및 월만 가져옵니다.django에서 시간 지우기 Django에서 DateTime
"2014-04-17T00:00:00"
나는 다른 기회를 보았다하지만
class Inventory(models.Model):
manufacturer = models.CharField(max_length=255)
model = models.CharField(max_length=255)
description = models.TextField(max_length=255)
count = models.IntegerField(max_length= 255, default=1)
location = models.ForeignKey('Location', null=True, blank=True)
cover = models.FileField(upload_to = 'static/images/', default = 'static/images/no-image.png')
created = models.DateTimeField(auto_now_add=True)
barcode = models.CharField(max_length=255)
assigned = models.ForeignKey(User, blank=True, null=True)
checked = models.BooleanField(default=False)
modified = models.DateTimeField(default=datetime.datetime.now)
tags = TaggableManager(through=None, blank=True)
def __unicode__(self):
return '%s' % date(self.modified, "n/j/Y")
def format_date(obj):
return obj.modified.strftime('%d %b %Y %H:%M')
format_date.short_description = 'Modified'
직접 귀하의 질문에 대답하지, 그런데 왜 당신은 그냥'하여 DateField를 사용하지 것이다 '? 또한'modified = models.DateTimeField (default = datetime.datetime.now)'대신'auto_now = True'를 사용할 수 있습니다. 변경 될 때마다 필드를 업데이트 할 것입니다. 'datetime.datetime.now'는 나중에 문제를 일으킬 수있는 TZ 비 인식 타임 스탬프입니다. – favoretti
'obj.modified.date(). isoformat()' –