Date string do not parsed to date object in Model.objects.create

11 views
Skip to first unread message

Mustafa Duman

unread,
May 29, 2014, 7:34:13 AM5/29/14
to django...@googlegroups.com
I have a model like:

    class SomeModel(Model):
        created = DateField(...)

I created an object using a date string (instead of date object)

    > new_rec = SomeModel.objects.create(created="2014-05-28")
    > new_rec.created
    >> "2014-05-28"
    > type(new_rec.created)
    >> str

While django save "created" field as date to my database, new_rec object keep it as a string since. When I retreive this record from database, it displayed as a normal date object.

    > rec = SomeModel.objects.get(id=...)
    > rec.created
    >> datetime.date(2014, 5, 28)

Problem is, django do not parse the the field value to related field type defied in Model and update the object on create operations.
 
Reply all
Reply to author
Forward
0 new messages