tags:

views:

20

answers:

1

Hi,

I am using django auth module.Now,when user logs in I want to record users ipaddress in the admin_log table.How can I do this?

thanks

+1  A: 

Create a middleware, that will be called after AuthenticationMiddleware is called (it must be spcified after the latter in settings.py). In this middleware retrieve ip address from HttpRequest.META attribute (it would be probably request.META['REMOTE_ADDR']) and add this information to the admin_log table. But is admin_log exactly the place where you would like to store this information?

gruszczy
what other options do I have? Basically,admin should be able to see when users are logging in and the ipaddress they are using.
jess
Why don't you create your own table for this information and show it in admin panel? `admin_log` is for operations made in admin panel, not for information about users logging in. I am not even sure, that you should store this kind of information in the database - maybe rather simply in log files? This can be done in a middleware too.
gruszczy
well the client wants to see in the admin section,so maybe I will go for custom table.
jess
I have got it working.But,now I want to execute it only once when user logs in for the first time
jess