-1

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?

Brian Tompsett - 汤莱恩
5,92772 gold badges64 silver badges135 bronze badges
asked Nov 22, 2010 at 12:09
3
  • What do you mean exactly, 'find the date data'? Commented Nov 22, 2010 at 12:13
  • I have stored some data for date, contact, item, status, user. I want to be able to see the data I put in for these objects using python manage.py shell. Not the admin. Commented Nov 22, 2010 at 12:24
  • Are you asking how to write command-line applications that use the Django ORM? stackoverflow.com/questions/3351951/… Commented Nov 22, 2010 at 12:31

2 Answers 2

1

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.

answered Nov 22, 2010 at 12:23
Sign up to request clarification or add additional context in comments.

Comments

0

When returning date to the python shell you could just use

from time import asctime
#print asctime()
answered Nov 22, 2010 at 12:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.