python - 从 Django 中的 DateTime 中删除时间

标签 python django

所以我需要从日期时间中删除,所以我只得到日期、年和月。

"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/

相关文章:

python - 用装饰器修补模块中的所有函数

python - 解释 scipy.stats.entropy 值

python - 如何在Python中合并标题列?

python - 如何将 numpy 数组转换为内存中的 pil 图像?

python - django 一个应用一个模型多个数据库

python - 如何在 Linux 中将 python 脚本作为服务运行

python - 使用 Whoosh 和 Django Haystack 时出现 ValueError

django - django 应用程序的自定义测试套件

python - 自定义 django runserver 输出

django - 使用 Selenium : Do I have any dead links? 的 Py/Django 单元测试