[damned-lies] Fix Person.get_by_attr when returning more than 1 result
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fix Person.get_by_attr when returning more than 1 result
- Date: Sat, 21 Sep 2013 09:33:01 +0000 (UTC)
commit f51cb20edbb0611066a3e23d99acd28f36bafa4b
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Sep 21 11:31:54 2013 +0200
Fix Person.get_by_attr when returning more than 1 result
In that case, take the Person object with most recent last_login
attribute.
people/models.py | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
---
diff --git a/people/models.py b/people/models.py
index 8a5bc5f..bd183b3 100644
--- a/people/models.py
+++ b/people/models.py
@@ -96,10 +96,9 @@ class Person(User):
if not val:
return None
try:
- person = Person.objects.get(**{key: val})
- except Person.DoesNotExist:
+ return Person.objects.filter(**{key: val}).order_by('-last_login')[0]
+ except IndexError:
return None
- return person
def save(self, *args, **kwargs):
if not self.password or self.password == "!":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]