0

I have a model called job and I want to set a datetime attribute (started_time) to MySQL now() value. how can I do that in Django?

I don't want to use the model auto_now or auto_now_add methods, since I have other applications who share the same DB and I don't want to handle timezones, thus I want to delegate that to MySQL

2 Answers 2

2

Don't use auto_now/auto_add_now, they are problematic. Instead, do this:

  started_time = models.DateTimeField(default=datetime.utcnow)

-- assuming that you're working with timestamps in UTC.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you expand on how they are problematic?
Google for "auto_add and auto_add_now in admin fieldsets". Also, they use datetime.now() which is dependent on os timezone settings. You might say that those are features - not issues, but for me the less magic the better.
0

Use MySQL trigger.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.