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
Shehzad009
1,6076 gold badges29 silver badges42 bronze badges
-
What do you mean exactly, 'find the date data'?Daniel Roseman– Daniel Roseman2010年11月22日 12:13:58 +00:00Commented 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.Shehzad009– Shehzad0092010年11月22日 12:24:27 +00:00Commented Nov 22, 2010 at 12:24
-
Are you asking how to write command-line applications that use the Django ORM? stackoverflow.com/questions/3351951/…S.Lott– S.Lott2010年11月22日 12:31:21 +00:00Commented Nov 22, 2010 at 12:31
2 Answers 2
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
Spacedman
94.7k12 gold badges148 silver badges232 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
When returning date to the python shell you could just use
from time import asctime
#print asctime()
answered Nov 22, 2010 at 12:15
Jakob Bowyer
34.8k8 gold badges80 silver badges93 bronze badges
Comments
lang-py