From 7716c619657f17c8411bbedc1c6eedbd5ca545dc Mon Sep 17 00:00:00 2001 From: oysteini Date: Sun, 6 Mar 2011 17:41:44 +0000 Subject: [PATCH] La til funksjon Book.get_persons. --- python/web/library/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/web/library/models.py b/python/web/library/models.py index c54696f..6824a4b 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -123,6 +123,11 @@ class Book(models.Model): authors.append(person.person) return authors + def get_persons(self, relation): + return map(lambda bp: bp.person, + filter(lambda bp: bp.relation.name == relation, + self.persons.all())) + def __unicode__(self): return self.title