Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Are we dropping auto_now and auto_now_add for 1.0?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  18 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
SmileyChris  
View profile  
 More options Apr 1 2007, 8:02 pm
From: "SmileyChris" <smileych...@gmail.com>
Date: Mon, 02 Apr 2007 00:02:04 -0000
Local: Sun, Apr 1 2007 8:02 pm
Subject: Are we dropping auto_now and auto_now_add for 1.0?
I'm not sure if there's a ticket for this, but I remember talk about
it being an unnecessary wart which was going to be removed eventually.
Is it in the 1.0 plan?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adrian Holovaty  
View profile  
 More options Apr 1 2007, 8:50 pm
From: "Adrian Holovaty" <holov...@gmail.com>
Date: Sun, 1 Apr 2007 19:50:20 -0500
Local: Sun, Apr 1 2007 8:50 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/1/07, SmileyChris <smileych...@gmail.com> wrote:

> I'm not sure if there's a ticket for this, but I remember talk about
> it being an unnecessary wart which was going to be removed eventually.
> Is it in the 1.0 plan?

Yes, I'd like to drop those two options.

auto_now can be accomplished with "default=datetime.datetime.now", and
auto_now_add can be accomplished with a custom save() method.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile  
 More options Apr 1 2007, 8:52 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Sun, 1 Apr 2007 19:52:48 -0500
Local: Sun, Apr 1 2007 8:52 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/1/07, SmileyChris <smileych...@gmail.com> wrote:

> I'm not sure if there's a ticket for this, but I remember talk about
> it being an unnecessary wart which was going to be removed eventually.
> Is it in the 1.0 plan?

Oh, please, yes!

I'd be inclined just to remove 'em wholesale and let things fail
loudly, but if someone wants to work up a patch that issues a
validation warning (and otherwise does nothing when those params are
there) that's probably the right approach.

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Apr 1 2007, 9:00 pm
From: "Russell Keith-Magee" <freakboy3...@gmail.com>
Date: Mon, 2 Apr 2007 09:00:42 +0800
Local: Sun, Apr 1 2007 9:00 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/2/07, Adrian Holovaty <holov...@gmail.com> wrote:

> On 4/1/07, SmileyChris <smileych...@gmail.com> wrote:
> > I'm not sure if there's a ticket for this, but I remember talk about
> > it being an unnecessary wart which was going to be removed eventually.
> > Is it in the 1.0 plan?

> Yes, I'd like to drop those two options.

> auto_now can be accomplished with "default=datetime.datetime.now", and
> auto_now_add can be accomplished with a custom save() method.

What about LazyDate? It seems to me that given
"default=datetime.datetime.now" is legal, LazyDate can be deprecated
as well.

Yours
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile  
 More options Apr 1 2007, 9:08 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Sun, 1 Apr 2007 20:08:57 -0500
Local: Sun, Apr 1 2007 9:08 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/1/07, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

> What about LazyDate? It seems to me that given
> "default=datetime.datetime.now" is legal, LazyDate can be deprecated
> as well.

Yeah, I'd like to get rid of LazyDate, too.

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Apr 1 2007, 9:11 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Mon, 02 Apr 2007 11:11:17 +1000
Local: Sun, Apr 1 2007 9:11 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?

Is there an easy way to say "today - 3 days" just using the datetime
module? I can't think of one off the top of my head that isn't as
complex as LazyDate(), but that may be because it's Monday.

At the moment LazyDate is useful in limit_choices_to and as a default
value. I'd vote to move it into django/utils/dates.py so that it's more
visible (it feels wrong in models/__init__.py, but that may just be my
bad taste), but I'd like to keep it. Otherwise I'm pretty sure I'm going
to end up rewriting it for myself.

Cheers,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Apr 1 2007, 9:21 pm
From: "Russell Keith-Magee" <freakboy3...@gmail.com>
Date: Mon, 2 Apr 2007 09:21:40 +0800
Local: Sun, Apr 1 2007 9:21 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/2/07, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:

> Is there an easy way to say "today - 3 days" just using the datetime
> module? I can't think of one off the top of my head that isn't as
> complex as LazyDate(), but that may be because it's Monday.

How about:

lambda : datetime.now() + datetime.timedelta(days=3)

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Apr 1 2007, 9:23 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Mon, 02 Apr 2007 11:23:34 +1000
Local: Sun, Apr 1 2007 9:23 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On Mon, 2007-04-02 at 11:11 +1000, Malcolm Tredinnick wrote:

[...]

> At the moment LazyDate is useful in limit_choices_to and as a default
> value.

Scrub that last part. Wishful thinking on my part. It can't really be
used as a default at the moment, because it doesn't have a __call__
method.

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Apr 1 2007, 9:26 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Mon, 02 Apr 2007 11:26:46 +1000
Local: Sun, Apr 1 2007 9:26 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?

On Mon, 2007-04-02 at 09:21 +0800, Russell Keith-Magee wrote:
> On 4/2/07, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:

> > Is there an easy way to say "today - 3 days" just using the datetime
> > module? I can't think of one off the top of my head that isn't as
> > complex as LazyDate(), but that may be because it's Monday.

> How about:

> lambda : datetime.now() + datetime.timedelta(days=3)

Yep, you're right. Must be Monday. :-(

I withdraw my objection. Nuke it.

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Honza Král  
View profile  
 More options Apr 1 2007, 9:37 pm
From: "Honza Král" <honza.k...@gmail.com>
Date: Mon, 2 Apr 2007 03:37:12 +0200
Local: Sun, Apr 1 2007 9:37 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On 4/2/07, Adrian Holovaty <holov...@gmail.com> wrote:

> On 4/1/07, SmileyChris <smileych...@gmail.com> wrote:
> > I'm not sure if there's a ticket for this, but I remember talk about
> > it being an unnecessary wart which was going to be removed eventually.
> > Is it in the 1.0 plan?

> Yes, I'd like to drop those two options.

> auto_now can be accomplished with "default=datetime.datetime.now", and
> auto_now_add can be accomplished with a custom save() method.

well, if I see this correctly, both have to be implemented in save().
Default will only be used if you don't supply a value, where auto_now
is used every time and cannot be overridden.

that said, I would be happy without them as well ;)

+1 on removing those options

> Adrian

> --
> Adrian Holovaty
> holovaty.com | djangoproject.com

--
Honza Král
E-Mail: Honza.K...@gmail.com
ICQ#:   107471613
Phone:  +420 606 678585

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
trbs  
View profile  
 More options Apr 2 2007, 12:52 pm
From: "trbs" <v.oostv...@gmail.com>
Date: Mon, 02 Apr 2007 09:52:48 -0700
Local: Mon, Apr 2 2007 12:52 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On Apr 2, 2:50 am, "Adrian Holovaty" <holov...@gmail.com> wrote:

> On 4/1/07, SmileyChris <smileych...@gmail.com> wrote:

> > I'm not sure if there's a ticket for this, but I remember talk about
> > it being an unnecessary wart which was going to be removed eventually.
> > Is it in the 1.0 plan?

> Yes, I'd like to drop those two options.

> auto_now can be accomplished with "default=datetime.datetime.now", and
> auto_now_add can be accomplished with a custom save() method.

> Adrian

It could be just me, but although i don't mind losing auto_*, it don't
look very DRY in save.

I know it's only a few lines (like 4 ? for both options, not using
default= for sake of keeping the logic together) but when lots of
models
have a cre_date and mod_date, those lines are repeated over and over
again in save().

Maybe a decorator or the dispatcher can help for all the models with
automaticly filled cre and mod_date's. This could also be combined
with
things like last_modified_by_user and created_by_user. Cause to me it
seems these are all standard (housekeeping) tasks which you would like
to associate with a model and not repeat the code for it in every
model.

But i could be missing the point entirely :) Malcolm's 'It's Monday'
comment could apply to me too ;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Beck  
View profile  
 More options Apr 6 2007, 2:15 pm
From: "Brian Beck" <exo...@gmail.com>
Date: Fri, 06 Apr 2007 18:15:09 -0000
Local: Fri, Apr 6 2007 2:15 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On Apr 2, 12:52 pm, "trbs" <v.oostv...@gmail.com> wrote:

> It could be just me, but although i don't mind losing auto_*, it don't
> look very DRY in save.

> I know it's only a few lines (like 4 ? for both options, not using
> default= for sake of keeping the logic together) but when lots of
> models
> have a cre_date and mod_date, those lines are repeated over and over
> again in save().

I agree. Using default= in place of auto_now_add is fine, but writing
a save() for every model that needs auto_now is just annoying. A
shortcut would be nice.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Larlet  
View profile  
 More options Apr 6 2007, 2:39 pm
From: "David Larlet" <lar...@gmail.com>
Date: Fri, 6 Apr 2007 20:39:25 +0200
Local: Fri, Apr 6 2007 2:39 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
2007/4/6, Brian Beck <exo...@gmail.com>:

> On Apr 2, 12:52 pm, "trbs" <v.oostv...@gmail.com> wrote:
> > It could be just me, but although i don't mind losing auto_*, it don't
> > look very DRY in save.

> > I know it's only a few lines (like 4 ? for both options, not using
> > default= for sake of keeping the logic together) but when lots of
> > models
> > have a cre_date and mod_date, those lines are repeated over and over
> > again in save().

> I agree. Using default= in place of auto_now_add is fine, but writing
> a save() for every model that needs auto_now is just annoying. A
> shortcut would be nice.

I agree with Brian.

Regards,
David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Beck  
View profile  
 More options Apr 6 2007, 4:08 pm
From: "Brian Beck" <exo...@gmail.com>
Date: Fri, 06 Apr 2007 20:08:22 -0000
Local: Fri, Apr 6 2007 4:08 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
Did people feel that save() was a better solution because it's already
a place where you have to put equivalent functionality for other
fields? I don't know why, but defining my own save() always seems like
a "big deal" that should be reserved for more complex stuff.

What about a new attribute for all fields, something like:
default_condition, where:

- The default is set if default_condition(current_value) is True.
- By default, default_condition is `lambda value: value is None`, this
mimicks current behavior.

So:
  # default_condition is True when created_date is None
  created_date = models.DateTimeField(default=datetime.now)

  # default_condition is always True, equivalent to auto_now=True
  updated_date = models.DateTimeField(default=datetime.now,
                                        default_condition=lambda
value: True)

And it's useful for other fields:

  minimum_of_zero = models.IntegerField(default=0,
                                             default_condition=lambda
value: value < 0)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Perry  
View profile  
 More options Apr 6 2007, 10:03 pm
From: Sean Perry <sha...@speakeasy.net>
Date: Fri, 6 Apr 2007 19:03:14 -0700
Local: Fri, Apr 6 2007 10:03 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
On Apr 6, 2007, at 11:39 AM, David Larlet wrote:

seems like it should be as easy as a function in contrib somewhere:

def auto_now(amodel):
         if not amodel.id:
             amodel.created = datetime.datetime.now()
         else:
             amodel.modified = datetime.datetime.now()

         super(type(amodel), amodel).save()

and in your model you have:

save = contrib.auto_now

When you have to add code to your save() method you could still call  
auto_now(self).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Kaplan-Moss  
View profile  
 More options Apr 6 2007, 10:12 pm
From: "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
Date: Fri, 6 Apr 2007 21:12:04 -0500
Local: Fri, Apr 6 2007 10:12 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
> seems like it should be as easy as a function in contrib somewhere:

[snip]

Another option is a trivial field subclass::

    class AutoDateTimeField(models.DateTimeField):
        def pre_save(self, model_instance, add):
            return datetime.datetime.now()

Jacob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joseph Perla  
View profile  
 More options Apr 6 2007, 10:19 pm
From: "Joseph Perla" <josephpe...@gmail.com>
Date: Fri, 6 Apr 2007 22:19:38 -0400
Local: Fri, Apr 6 2007 10:19 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?

+1.  Follows DRY.  An AutoDateTimeField is very common.
j

On 4/6/07, Jacob Kaplan-Moss <jacob.kaplanm...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug.napoleone@gmail.com  
View profile  
 More options Apr 6 2007, 10:53 pm
From: "doug.napole...@gmail.com" <doug.napole...@gmail.com>
Date: Sat, 07 Apr 2007 02:53:50 -0000
Local: Fri, Apr 6 2007 10:53 pm
Subject: Re: Are we dropping auto_now and auto_now_add for 1.0?
I made this suggestion on the django board.

@auto_now('updatted_on')
@auto_add_now('submitted_date')
def save(self):
    super(MyModel).save()

I even have started coding it as I need SOME solution that is simple.
One problem I have had is with edit_inline and auto_now where the
entries are always updated in teh admin even if nothing was changed.
Also there are sometimes when I want an auto_now on condition. So this
all boils down to something like

def auto_now(save, *field_names, **options):
    condition = None
    if 'condition' in options: condition = options['condition']
    if not len(field_names): raise InvalidArgument, "Something..."
    save = save
    field_names = field_names
    def auto_now_decorator(object):
        if condition is not None:
            if not condition(object): return
        for name in field_names:
            setattr(object, name, datetime.datetime.now())
        save(object)
    return auto_now_decorator

def auto_add_now(save, *field_names, **options):
    base_condition = None
    if 'condition' in options:
        base_condition = options['condition']
    def new_condition(object):
        ## add code to get models PK field from type(object).
        pk = 'id'
        if getattr(object, pk) is None:
            if base_condition is not None:
                return base_condition(object)
            return True
        return False
    options['condition'] = new_condition
    return auto_now(save, *field_names, **options)

This would allow for things like:

@auto_now('last_saved_on', 'other_field')
@auto_now('updated_on', condition = lambda obj:
fields_have_changed(object))
## only set the datetime on new objects if the field is not already
set...
@auto_add_now('submitted_date', condition=lambda obj:
obj.submitted_date is None)
def save(self):
    ## some other custom code....
    super(MyModel, self).save()

To be honest this could be abstracted further where the dynamic value
could be set lazy, (like in the previous post has on the model
fields).
I perfer having these as decorators so they can be added to ANY save
'like' method or on the form it's self.
I also used the term 'dynamic' on purpose, as this is not a default
value, but could be set to anything based on any of the other fields
or any outside influence.

There are problems with the above code, the PK issue is mentioned, but
there are also issued with time vs data vs datetime vs strings, and
giving proper errors for fields which do not exist.
I would also want another option for doing backoff validation but that
is for a separate post.
I would love any feedback anyone has on this Idea. There are a number
of projects I am working on that will need this (PyCon, python Jobs
board, and 3 others), so I plan on doing a formal implementation
starting soon.

    -Doug

On Apr 6, 10:03 pm, Sean Perry <sha...@speakeasy.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »