Gacha wrote: > I created a simple model "articles" and I added field: > author = meta.ForeignKey(User,editable=False) > > When I add new artcicle I want to assign to this field the current user > ID, but so far no luck :( > > I tryed: > def _pre_save(self): > from django.models.auth.users import User > self.author = User.id > > But it say's that User has no id :(
Of course. In this code, "User" refers to the User *class*, not to an instance of that class representing the current user. > I think that other method is to get the ID from "request.user.id", but > I don't know how to get this in _pre_save() function. You can't. This would imply passing the request object to the model - but then the model would depend on the execution context. A model should be reusable in different execution contexts - which is easier to achieve if the model is ignorant of the execution context. -- bruno desthuilliers développeur [EMAIL PROTECTED] http://www.modulix.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---