Re: getting id of logged user in admin site

2005-11-02 Thread Flavio Curella

hello gregory,

ticket is #714.

bye,
Flavio



Re: getting id of logged user in admin site

2005-11-02 Thread Grigory Fateyev

Hello Flavio Curella!
On Tue, 01 Nov 2005 16:45:08 -0800 you wrote:

> 
> thanks Hugo.
> 
> I think this is a common case: I (and peraphs many people) prefer
> django to other frameworks because of its admin application: half a
> work is already made. I think a feature like this will be very helpful
> to many people, so I will open a ticket on django's trac.

It is very interestingc for me. What is the number of ticket?

-- 
Всего наилучшего!
greg [at] anastasia [dot] ru Григорий.


Re: getting id of logged user in admin site

2005-11-01 Thread Flavio Curella

thanks Hugo.

I think this is a common case: I (and peraphs many people) prefer
django to other frameworks because of its admin application: half a
work is already made. I think a feature like this will be very helpful
to many people, so I will open a ticket on django's trac.

Thanks to all,
Flavio Curella.



Re: getting id of logged user in admin site

2005-11-01 Thread hugo

>What I want to do is to save the article with the id of user that is
>saving the article, without the need to select an user/author from a
>menu.

The model code doesn't have access to the request, so you are out of
luck. It's simple to do in your own applications (as you have full
control over your views there), but I don't think it's so simple with
the admin, as that's a prebuilt application and you don't have too much
ways to hook into the view functions - only into the model behaviour.

bye, Georg



Re: getting id of logged user in admin site

2005-11-01 Thread Joey Coleman

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