开发者

Want to find date data in python shell

开发者 https://www.devze.com 2023-01-26 21:14 出处:网络
I have a model something like this. #models.py class ItemStatusHistory(models.Model): date = models.DateTimeField(auto_now = True)

I have a model something like this.

#models.py
class ItemStatusHistory(models.Model):
    date = models.DateTimeField(auto_now = True)
    contact = models.ForeignKey(Contact)
    item = models.ForeignKey(StorageItem)
    status = models.ForeignKey(Status)
    user = models.ForeignKey(User)

    def __unicode__(self):
        return str(self.status)

I want to be able to 开发者_运维问答find the date data using

python manage.py shell

But I want to keep the unicode object as status. Do I use a filter lookup?


Get the object from the django db in the usual way and access foo.name_of_attribute:

The example in the django docs should help, see:

http://docs.djangoproject.com/en/dev/intro/tutorial01/

 >>> p = Poll.objects.get(pk=1)
 >>> p.pub_date
 datetime.datetime(2007, 7, 15, 12, 00, 53)

And thats a standard python datetime thing.


When returning date to the python shell you could just use

from time import asctime
#print asctime()
0

精彩评论

暂无评论...
验证码 换一张
取 消