On Apr 6, 2007, at 11:39 AM, David Larlet wrote:

>
> 2007/4/6, Brian Beck <[EMAIL PROTECTED]>:
>>
>> On Apr 2, 12:52 pm, "trbs" <[EMAIL PROTECTED]> 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.
>

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 received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to