I have a Django model as described here
I create and save an instance of this model:
>>> from django.db.models import Max, F, Func
>>&
The primary difference between datetime and timestamp is that timestamp will automatically store a value as UTC, using the current mysql time_zone setting, and datetime will ignore the time_zone setting when inserting and retrieving records.
You're using a datetime field, however you're also using the mysql UNIX_TIMESTAMP function against that field. When you do that, the docs explain that the server interprets the value as a local time value, based on the time_zone setting. This is the source of the conversion discrepancy.
You have two choices.
time_zone session variable is set to UTC before running your query.timestamp field instead of a datetime field.