Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

La til reference i to_dict. #6

This commit is contained in:
Andreas Lindahl Flåten 2011-03-05 18:07:24 +00:00
parent 804ef55192
commit 1a9bf1a915
1 changed files with 19 additions and 3 deletions

View File

@ -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