If your using auto_now_add, then you should want the date auto-populated *every* time. If that is not the behavior you want, then writing you own save method can easily give you the behavior you want.
Actually, in your case, you probably want auto_now_add's behavior all the time. That is with the one-time exception of importing your old data. The thing is, auto_now_add's inclusion or exclusion from the model has no effect on the db, so while running your import script you could have commented out or removed the reference to auto_now_add and added it back after the script was done. Not that big of a deal considering you'll likely never run that script again on that model. On 7/4/07, Noam <[EMAIL PROTECTED]> wrote: > > Hello, > > I wrote a script to convert from an old database (turbogears) to > django. It involved a few loops like this: > > for oldm in messages: > newm = models.Message() > newm.date = oldm.date > newm.text = oldm.text > newm.save() > > After running the script, I discovered that all the messages in the > new DB had the same date. This was very strange, because everything > else was ok. This was even more strange, because this worked fine: > > >>> m = models.Message.objects.get(id=1) > >>> m.date = datetime(2007, 4, 4) > >>> m.save() > > It took me a very long and unpleasant hour to discover that it was > because the date field had auto_now_add=True. I fixed my script, so > now the loop looks like this: > > for oldm in messages: > newm = models.Message() > newm.text = oldm.text > newm.save() > newm.date = oldm.date > newm.save() > > The conclusion is that auto_now_add should set the date only if it is > None. Or, another solution: it should set the date upon instance > creation, not upon saving. > > Do you agree? > > Noam > > > > > -- ---- Waylan Limberg [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---