Best way to store year only 'YYYY' dates

8 views
Skip to first unread message

rayjowa

unread,
Nov 30, 2015, 10:11:49 AM11/30/15
to Zimbabwe Python Users Group
Hi Guys, 

I'm working on a module and I want to store vehicle 'year of make'.  

Can you recommend the best field type in Django.  I'm considering either a DateField and setting the month and date to 1 or just using an IntegerField.

The only foreseeable calculations that will be needed are determining age of a vehicle. 

Ray  

Humphrey

unread,
Nov 30, 2015, 12:22:15 PM11/30/15
to zi...@googlegroups.com



-------- Forwarded Message --------
Subject: Re: [zimpy] Best way to store year only 'YYYY' dates
Date: Mon, 30 Nov 2015 18:56:46 +0200
From: Humphrey <hbut...@gmail.com>
To: rayjowa <ray...@gmail.com>


Hi Ray!

What if u you use DateTimeField?

Cheers
--
You received this message because you are subscribed to the Google Groups "Zimbabwe Python Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zimpy+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/zimpy.
To view this discussion on the web, visit https://groups.google.com/d/msgid/zimpy/21d57bc1-7f8a-484b-b182-59bf896248d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Humphrey Butau
President: Zimbabwe Python User Group
+263777216561

This e-mail was sent from a notebook running Ubuntu Vivid Vervet


Anna Makarudze

unread,
Dec 1, 2015, 1:34:56 PM12/1/15
to Humphrey, zi...@googlegroups.com
I was going to suggest that too.

rayjowa

unread,
Dec 2, 2015, 12:19:53 AM12/2/15
to Zimbabwe Python Users Group
Thanks guys.  I'll provide feedback when I test.  Are there any arguments I need to set to make it accept input like 2000 as a DateTime?

Humphrey

unread,
Dec 2, 2015, 1:32:32 AM12/2/15
to zi...@googlegroups.com
Hie Ray,

You could do it like this:

 class Post(models.Model):
     time_bought = models.DateTimeField(auto_now_add=True, blank=True)

     def get_age_diff(self):
       age = age = datetime.datetime.now() - self.time_bought
         print age # this line is never executed
         return age

Cheers
--
You received this message because you are subscribed to the Google Groups "Zimbabwe Python Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zimpy+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/zimpy.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages