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