Comments (7)
app engine does a good job with this.
(from http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#DateTimeProperty)
If auto_now is True, the property value is set to the current time whenever the model instance is stored in the datastore, overwriting the property's previous value. This is useful for tracking a "last modified" date and time for a model instance.
If auto_now_add is True, the property value is set to the current time the first time the model instance is stored in the datastore, unless the property has already been assigned a value. This is useful for storing a "created" date and time for a model instance.
from schematics.
Yeah this is really helpful in django apps. I'd like to see it here too
from schematics.
I think it's a great feature, but isn't auto_now
and auto_now_add
a little cryptic? From an ORM perspective (see e.g. PHP Doctrine, Ruby) these would be more likely to be called create_timestamp
and update_timestamp
or similar...
from schematics.
Sorry I spoke too soon - DictShield doesn't have any way of knowing if a record is new or existing, so auto_now_add
becomes a non-issue. I think auto_now
is a fine name
from schematics.
I took a look at this last night. Dictshield doesn't have a pre-persist hook. Which it shouldn't, since it doesn't even really include the notion of persistence. How should this work? When you create a dictshield with auto_now=True the field is set? Then when you import data from a persistence layer, it would blow it away? That's what makes sense to me. Thoughts?
from schematics.
Agree with all of that @gone - especially that DictShield should not have a pre-persist hook. Keen that DictShield stays usage-agnostic (I don't use it for persistence at all - just for typesafe JSON (un)marshalling)...
from schematics.
I like the idea of auto_now, but you can also set the DateTimeField's default value to datetime.datetime.now
, without the parenthesis, and it will call that function every time a model is instantiated. It's perhaps nto quite as explicit but you can still set the field to default to the time of instantiation.
I'm going to close this for now unless a good argument for being explicit is made. :)
from schematics.
Related Issues (20)
- When using multiple inheritance, rogue field errors for any inherited models
- ListType serialize_when_none=False doesn't seem to work HOT 1
- Serializable property is not filled when import data
- ETA for a new release HOT 7
- HashType requires LENGTH HOT 1
- SyntaxWarning with a literal
- Fix simple typo: overriden -> overridden HOT 2
- BaseType's has no attribute 'model_class' HOT 2
- RecursionError when using @serializable HOT 2
- Have you considered the possibility to replace blacklist/whitelist terminology by using better terminology?
- Project is still being maintened HOT 9
- Request for joining the organisation
- I want To Join this organization.
- Question: PolyModelType that selects Model based on field value of parent HOT 1
- Question: Parsing data between JSON schemas HOT 1
- schematics.exceptions.ConversionError: [u'No default or explicit locales were given.'] HOT 1
- Python 3.10 - Schematics finally broke HOT 4
- cannot collect all model errors HOT 1
- the traceback including the line number where the validation error occurred
- Question: How to deal with models referencing each other? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schematics.