Lucas Ou Lucas Ou - 1 year ago 159
Python Question

Django saves records using "old" time

This issue has been occurring on and off for a few weeks now, and it's unlike any that has come up with my project.

Two of the models that are used have a timestamp field, which is by default set to

This is the sequence that raises error flags:

  • Model one is created at time 7:30 PM

  • Model two is created at time 10:00 PM, but in the
    MySQL database it's stored as 7:30 PM!

Every model that is created
has its time stamp saved under 7:30 PM, not the actual time, until a certain
duration passes. Then a new time is set and all the following models
have that new time... Bizzare

Some extra details which may help in discovering the issue:

I have a bunch of methods that I use to strip my timezones of their
's and replace them with UTC.

This is because I'm doing a - creationTime
calculation to create a: "model was posted this long ago" feature
in the project. However, this really should not be the cause of the problem.

I don't think using
will make any difference either.

Anyway, thanks for the help!

Answer Source

Just ran into this last week for a field that had If you remove the parentheses (in this case, try then you're passing a callable to the model and it will be called each time a new instance is saved. With the parentheses, it's only being called once when loads.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download