I’ve recently been playing around with the Django web framework (all non-techies should stop reading this at once). Here’s a little snippet of code that’s useful if you want to add a timestamp to a model you’re creating:
from datetime import datetime
class My_Model(models.Model):
date_created = models.DateTimeField()
date_modified = models.DateTimeField()
def save(self):
if self.date_created == None:
self.date_created = datetime.now()
self.date_modified = datetime.now()
super(My_Model, self).save()
What happens is that when you save the object, you override the Django save method with your own. It checks to see if the object has a date_created timestamp. If it doesn’t (i.e., you’re creating it for the first time), it adds one. It also updates the date_modified timestamp every time you save it.
You might be wondering: why not just set the model to look like this:
date_created = models.DateTimeField(default=datetime.now())
It won’t work due to a quirk in Python. Python will calculate “now” to be the time when the model is loaded into interpreted. This means that every single object, until you restart the server, will get exactly the same timestamp. Not too useful - so use this hack instead.
It’s pretty much impossible to predict the future - particularly for something as fast moving as the Internet. However, as part of Mozilla’s Concept Series, Adaptive Path has created a few videos (bonus: watch ‘em in HD) on what the future of the browser might be.
Essentially, the browser is the web - and your computer. Everything is happening in the cloud and the browser is the container for all applications (whether communication, search, etc.) to occur. One of the interesting aspects is that it involves web services seamlessly transferring data from one to another.
This has been the holy grail for folks for years, but it continually seems to get blocked (mainly due to a lack of standards or a proliferation of competing standards by large incumbents with entrenched interests). However, it’s starting to occur.
Here’s an interesting example. I work at WebMD and we have a partnership with Yahoo to serve you ads on Yahoo properties based upon your browsing history at WebMD. This means that we share our data with them (although they don’t actually know what you saw; they just receive the ad). Recently, I was testing out WebMD’s Rheumatoid Arthritis (RA) Health Check - and when I went to Yahoo News, check out the ad on the right hand side:
This is just a baby step, but I’m looking forward to the day when web services are constantly sharing data. Things are going to get very interesting. Hopefully it won’t create Skynet.