Try the following: On 10/27/05, Flavio Curella <[EMAIL PROTECTED]> wrote: > > hi all, I've this model: > > from django.core import meta > from django.models.auth import User > > class Article(meta.Model): > title = meta.CharField(maxlength=255) > content = meta.TextField() > author = meta.ForeignKey(User) // problem is here, I think > categories = meta.ManyToManyField(Category) > creation_date = meta.DateTimeField('creation date', auto_now_add=True) > mod_date = meta.DateTimeField('modification date', auto_now=True) > file = meta.FileField(upload_to='/Users/go/Sites/django/files/') > > class META: > admin = meta.Admin( > fields = ( > (None, {'fields': ('title', 'content', > 'categories') > }), > ), > ) > > How can I save the field 'author' with the id of current user? I think > to use 'default' attribute, something like this: > author = meta.ForeignKey(User, default=???) > but how can I get current uesre's id? (user.id doesn't work) >
That code above should work fine (I'm using almost precisely that in something I'm working on). Try something like this to get the id: >>> a = articles.get_list()[0] >>> auth = a.get_author() >>> auth.id cheers, --joey