Skip to content

Commit

Permalink
Set last_login on create_user for backward compatibility
Browse files Browse the repository at this point in the history
`User.last_login` default is removed from django > 1.7.0. For existing
project using `django-user-management` project migrations would be run
after `django.contrib.auth` migrations and will cancel last_login `IS
NULL`.
  • Loading branch information
Kevin Etienne committed Sep 18, 2014
1 parent ea48bd3 commit a069350
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions user_management/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def create_user(self, email, password=None, **extra_fields):
email = self.normalize_email(email).lower()
user = self.model(
email=email,
last_login=timezone.now(),
**extra_fields
)
user.set_password(password)
Expand Down
6 changes: 6 additions & 0 deletions user_management/models/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def test_create_user_uppercase_email(self):
user = self.manager.create_user(email)
self.assertEqual(email.lower(), user.email)

def test_set_last_login(self):
email = 'valid@example.com'

user = self.manager.create_user(email)
self.assertIsNotNone(user.last_login)

def test_create_superuser(self):
email = 'valid@example.com'
password = 'password'
Expand Down

0 comments on commit a069350

Please sign in to comment.