Q:

Compare saved date field with new unsaved object

I'm triying to update a record if the date is the same.
To do that, I retrieve the last record using:
saved_object = TheModel.objects.latest("date")
new_object  = TheModel.objects.create(date="2014-12-15")

And then I compare the dates using:
if saved_object.date == new_object.date:
    doStuffWithTheSavedObject()
    saved_object.save() # update
else:
    new_object.save() # insert new one

Looking at the database, I see that the dates are the same so the if statement is returning false. After debuggin it, I see that the new_object.date is a str and not a date type as I thought it should be.
My question is, how can I prepare the new_object so it has a date field with the right type without saving it into the database and without passing it a casted date manually.
Regards
Update:
class TheModel(models.Model):
    date = models.DateField()
    a = models.IntegerField()
    b = models.IntegerField()
    c = models.IntegerField()

A:

Use datetime.date or datetime.datetime (for DateField or DateTimeField accordingly):
import datetime
new_object = TheModel(date=datetime.date(2014, 12, 15))

if you have date as string on input, use strptime
new_object = TheModel(
    date=datetime.datetime.strptime('2014-12-15', '%Y-%m-%d'))

