-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: auto_now and auto_now_add options for DateTimeField #21
Comments
Well I'd suggest using signals, but it all depends on how you update your documents. Doing a You can set a default which covers |
Well, I've just noticed once more callable defaults and see And yes, I understand that implementing Also, I think that documenting design principles for |
I dont think its a scary task - should be relatively trivial, its just we'd have to hook into every save (easy) and inject into every update call - maybe unexpected for the user. I'll schedule for post 0.7 - but it might make 0.7 |
Thank you very much! Now I may try to contribute some code on this task. Not promising that I will though. |
Having to bump to 0.8 as PY3 support came early! |
damn... how do I deactivate this :)) |
So is this supported now? In which version? Thanks! |
Look at the following code snippet, it will clarify. class Post(models.Model):
title = models.CharField(max_length=50, blank=False)
description = models.TextField()
pic = models.URLField(max_length=1000) #default max_length is 200
created = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
posted_by = models.ForeignKey(User, on_delete=models.CASCADE) # "User" => won't work
def __unicode__(self):
return self.title |
@hygull it's seem like that model by django,is really supported in mongo too? |
@lvtuben Yes it supports. We can check this at Using MongoDB as your primary Django database. |
@hygull In which version, does it work? I am using |
Why unsure of this feature if it is already implemented? |
Just to clarify, |
Can you please check https://staltz.com/djangoconfi-mongoengine/#/9 |
Can you please check https://staltz.com/djangoconfi-mongoengine/#/9 |
Don't attempt str.decode in PY3
This is really very useful! |
This is very useful. I wonder why wouldn't it be part of the package... I am forced to overload the save() function for every model class to add it. |
This is probably not going to be added since passed 11 years already. |
There are two very useful options for DateTimeField in Django: auto_now and auto_now_add.
From django docs:
"""
auto_now
Automatically set the field to now every time the object is saved. Useful for "last-modified" timestamps. Note that the current date is always used; it's not just a default value that you can override.
auto_now_add
Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it's not just a default value that you can override.
"""
I think it is very simple task to implement
auto_now_add
behavior at least. I understand that implementingauto_now
is a bit harder. By the way the fact that MongoEngine still has no support for these options lets me think that this is done by design. Which is not right by my personal opinion.The text was updated successfully, but these errors were encountered: