Monday, December 22, 2014

Re: How to Display the number of active users in Django Site with IP address

Hi,

Something like this might be a start:

class UserIP(models.Model):
    user
= models.ForeignKey(User)
    ip
= models.GenericIPAddressField()
    last_seen
= models.DateTimeField(auto_now=True)

class Middleware(pass):
   
def process_response(request, response):
       
if request.user:  # or getattr(request, '_cached_user')
           
UserIP.objects.create_or_update(user=request.user, ip=request.META['REMOTE_ADDR'])
       
return response

Collin

On Sunday, December 21, 2014 7:30:33 AM UTC-6, Avinash Kunuje wrote:
How to Display the number of active users in Django Site with IP address

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd4d971c-d5f4-409b-bec4-96427c3841f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment