GithubHelp home page GithubHelp logo

Comments (7)

robspychala avatar robspychala commented on May 17, 2024

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.

gone avatar gone commented on May 17, 2024

Yeah this is really helpful in django apps. I'd like to see it here too

from schematics.

alexanderdean avatar alexanderdean commented on May 17, 2024

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.

alexanderdean avatar alexanderdean commented on May 17, 2024

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.

gone avatar gone commented on May 17, 2024

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.

alexanderdean avatar alexanderdean commented on May 17, 2024

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.

j2labs avatar j2labs commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.