On 3/27/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Mon, 2007-03-26 at 21:56 +0200, Gilhad wrote: > > I am trying to get current user, but I have some problem with it. I got > > different '_local' object each time ... > > > > I followed the example at > > http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser > > > > and make my model such way: > > > > class Vykon(models.Model): > > user = models.ForeignKey(User, default=threadlocals.get_current_user, > > blank=True, null=True) > > This line is executed (and evaluted) exactly once, at import time. So > the way you are setting the default will not work as you expect. > > > > otherField = models.DateTimeField() > > def save(self): > > if not self.user: > > u=threadlocals.get_current_user() > > This line is executed whenever you call Vykon.save() > > > self.user = u.id > > super(Vykon,self).save() > > > > I'm not entirely sure what you are trying to do here, but the > construction of your user field in the model is not going to work > correctly (the default value will be wrong), so that might be the cause > of your troubles.
the default value is a callable, its not a value... I use exactly this and it work very well for me... I agree that there is duplicity (why specify a default if you override it in save() ), but that shouldn't matter > > Regards, > Malcolm > > > > > -- Honza Kr�l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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-users?hl=en -~----------~----~----~----~------~----~------~--~---