0

I just migrated to Django 1.5. But I am having a some difficulties to work with AUTH_USER_MODEL. Look the following example, I just can't update a value in the database. What I am doing wrong?

Test 1

user = get_user_model().objects.get(id=3)
user.email
u'zzzzz@gmail.com'
user.is_active
False

user.is_active = True
user.save()

user = get_user_model().objects.get(id=3)
user.is_active
False

Test 2

user.email
u'zzzzz@gmail.com'
user.email='blah@blah.com'
user.save()

user = get_user_model().objects.get(id=3)
user.email
u'zzzzz@gmail.com'

Teste 3 The same happens with MyUser model

from myuser.models import MyUser
a = MyUser.objects.get(id=3)
a.is_active
False
a.is_active = True
a.save()
a = MyUser.objects.get(id=3)
a.is_active
False
Thomas
  • 2,256
  • 6
  • 32
  • 47

1 Answers1

1

@Catherine and @Sid were correctly! Thanks Guys!

In my save method I forget to indent super().

It was:

def save(self, *args, **kwargs):

    if not self.hash:
        now = time.localtime(time.time())
        time_formatted=time.strftime("%Y-%m-%d %H:%M:%S", now)
        hash="%s%s" % (time_formatted, self.email)
        self.hash=hashlib.sha1(hash).hexdigest()
        super(MyUser, self).save(*args, **kwargs)

when the correct is:

def save(self, *args, **kwargs):
    if not self.hash:
        now = time.localtime(time.time())
        time_formatted=time.strftime("%Y-%m-%d %H:%M:%S", now)
        hash="%s%s" % (time_formatted, self.email)
        self.hash=hashlib.sha1(hash).hexdigest()
    super(MyUser, self).save(*args, **kwargs)
Thomas
  • 2,256
  • 6
  • 32
  • 47