Changes between Version 40 and Version 41 of IrcFAQ

07/18/2007 01:13:35 AM (8 years ago)



  • IrcFAQ

    v40 v41  
    134134Both mod_python and FastCGI are structured in such a way that there's no such thing as "application startup" or "server startup"; the best solution is to place your "startup" code somewhere that's guaranteed to be imported early on in the request/response cycle (the `` file of your project, or of a specific application you're using, can be a good place, because Python will execute code found there the first time it has to import the module; just be aware that referencing the same module in different ways, say by doing `from myproject.myapp import foo` in one place, and `from myapp import foo` in another, will cause that code to be executed once for each different way you import it).
     136== I have a `DateField` or `DateTimeField` with a default value of `now()`, but it's not working! ==
     138What you've probably done is something like this:
     141some_date_field = models.DateTimeField(
     144When you do that you're immediately calling `` and passing its return value -- ''at the moment the class is defined'' -- to be the default, which means it will not change during the life of a server process. What you want to do instead is this:
     147some_date_field = models.DateTimeField(
     150Note that there are no parentheses on `` in this version, so you're passing ''the function itself'' to be the default. When Django receives a function as a default value for a model field, it will call the function each time a new object is saved, and that will correctly generate the current date/time for each object.
Back to Top