La til to_string og to_dict for Person. #5
This commit is contained in:
@@ -160,14 +160,25 @@ class Person(models.Model):
|
||||
def to_string(self, commit=False):
|
||||
if commit:
|
||||
#generate commit-string
|
||||
print ''
|
||||
print self.to_dict()
|
||||
else:
|
||||
scratch = 'Name'.ljust(15, ' ') + ':'
|
||||
scratch += ' '.join((first_name,last_name))
|
||||
format = '%-10s: %50s \n'
|
||||
scratch = format % ('Name', ' '.join((self.first_name, self.last_name)))
|
||||
scratch += format % ('ID', self.id)
|
||||
|
||||
books = ', '.join(map(lambda x: x.book.title, self.books.all()))
|
||||
scratch += format % ('Books', books)
|
||||
|
||||
return scratch
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
dict = {}
|
||||
dict['action'] = 'edit-person'
|
||||
dict['id'] = self.id
|
||||
dict['first_name'] = self.first_name
|
||||
dict['last_name'] = self.last_name
|
||||
|
||||
return dict
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
|
Reference in New Issue
Block a user