Forandret litt på Book.to_dict.
Setter hvert felt eksplisitt istedenfor å ha en løkke med magi, for noen av feltene trenger litt spesialbehandling.
This commit is contained in:
parent
0c2130db3e
commit
8eafa21103
|
@ -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'] = {}
|
||||
|
|
Reference in New Issue