From 1a9bf1a915c7d33cd90bfae79a973dabfa299474 Mon Sep 17 00:00:00 2001 From: andrfla Date: Sat, 5 Mar 2011 18:07:24 +0000 Subject: [PATCH] La til reference i to_dict. #6 --- python/web/library/models.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/python/web/library/models.py b/python/web/library/models.py index 91904a9..333449f 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -80,9 +80,12 @@ class Book(models.Model): else: dict['persons'][person.relation.name] = [person.id] - dict['references'] = [] - #for reference in self.references: - # dict['references'].append(reference.text) + dict['references'] = {} + for reference in self.references.all(): + if person.relation.name in dict['references']: + dict['references'][reference.reference_type.name].append(reference.text) + else: + dict['references'][reference.reference_type.name] = [reference.text] #TODO: add thumbnail and image fields @@ -151,6 +154,19 @@ class Person(models.Model): last_name = models.CharField(max_length=255) references = models.ManyToManyField(Reference, related_name='persons', null=True, blank=True) + def to_string(self, commit=False): + if commit: + #generate commit-string + print '' + else: + scratch = 'Name'.ljust(15, ' ') + ':' + scratch += ' '.join((first_name,last_name)) + + return scratch + + + + def __unicode__(self): return self.first_name + u' ' + self.last_name