From 8eafa21103dc1cce35292d877e1fd5044f1f96fd Mon Sep 17 00:00:00 2001 From: oysteini Date: Sun, 6 Mar 2011 15:44:05 +0000 Subject: [PATCH] =?UTF-8?q?Forandret=20litt=20p=C3=A5=20Book.to=5Fdict.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setter hvert felt eksplisitt istedenfor å ha en løkke med magi, for noen av feltene trenger litt spesialbehandling. --- python/web/library/models.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/python/web/library/models.py b/python/web/library/models.py index e9f64e5..2e646f9 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -68,11 +68,20 @@ class Book(models.Model): def to_dict(self): dict = {} dict['action'] = 'edit-book' - for field in book_fields: - try: - dict[field[0]] = eval('self.'+field[0]) - except AttributeError: - dict[field[0]] = ' ' + + dict['isbn'] = self.isbn + dict['title'] = self.title + dict['category'] = self.category.id + dict['subtitle'] = self.subtitle + dict['publisher'] = self.publisher + dict['published_year'] = self.published_year + dict['edition'] = self.edition + dict['num_pages'] = self.num_pages + if self.series: + dict['series'] = self.series.id + else: + dict['series'] = '' + dict['description'] = self.description people = self.persons.all() dict['persons'] = {}