Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect update_last_login?

I implemented my own User class from scratch in Django. But when I log in I have this error:

The following fields do not exist in this model or are m2m fields: last_login

I really don't want the field last_login.

I do some reasearch and the problem is here: contrib.aut.models.py

def update_last_login(sender, user, **kwargs):
    """
    A signal receiver which updates the last_login date for
    the user logging in.
    """
    user.last_login = timezone.now()
    user.save(update_fields=['last_login'])
user_logged_in.connect(update_last_login)

I found a workaround but it's not an ellegant solution. I added user_logged_in.disconnect(update_last_login) in my models.py file, where my User class is defined.

Is there any better solution for this?

like image 691
Brais Gabin Avatar asked Mar 01 '15 18:03

Brais Gabin


1 Answers

Not sure if this is related to a newer version of django or what, but in my case

user_logged_in.disconnect(update_last_login)

didn't work. This is what works for me (django 2.1):

user_logged_in.disconnect(update_last_login, dispatch_uid='update_last_login')
like image 76
Sergio Morstabilini Avatar answered Oct 19 '22 23:10

Sergio Morstabilini