所以我需要从日期时间中删除,所以我只得到日期、年和月。
"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'
最佳答案
这对我有用。
def get_date(self):
return self.modified.date()
关于python - 从 Django 中的 DateTime 中删除时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23261987/