diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-10-24 16:42:03 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-10-24 16:42:03 +0000 |
| commit | 179d410a7acbb93a6d089a2184b09fead4b263ec (patch) | |
| tree | 5e29d98e723eb8ec4be59dd5bb32527932140f0f | |
| parent | cacbedee277b9b03fe65282db201617cbaad38b2 (diff) | |
Fixed #2937 -- Added __eq__, __ne__ and __hash__ for AnonymousUser. Thanks, favo@exoweb.net
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3924 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/auth/models.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 73bcfe92aa..b149477c46 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -126,7 +126,7 @@ class User(models.Model): def is_anonymous(self): "Always returns False. This is a way of comparing User objects to anonymous users." return False - + def is_authenticated(self): """Always return True. This is a way to tell if the user has been authenticated in templates. """ @@ -270,6 +270,15 @@ class AnonymousUser(object): def __str__(self): return 'AnonymousUser' + def __eq__(self, other): + return isinstance(other, self.__class__) + + def __ne__(self, other): + return not self.__eq__(other) + + def __hash__(self): + return 1 # instances always return the same hash value + def save(self): raise NotImplementedError @@ -301,6 +310,6 @@ class AnonymousUser(object): def is_anonymous(self): return True - + def is_authenticated(self): return False |
