add_author method
parent
29baf69d3c
commit
a5d3dfdf4f
|
@ -202,8 +202,7 @@ def update_edition(edition):
|
|||
models.Identifier.get_or_add(type='goog',value=googlebooks_id,edition=edition,work=edition.work)
|
||||
|
||||
for a in d.get('authors', []):
|
||||
a, created = models.Author.objects.get_or_create(name=a)
|
||||
a.editions.add(edition)
|
||||
edition.add_author(a)
|
||||
|
||||
add_ebooks(item, edition)
|
||||
|
||||
|
|
|
@ -1634,6 +1634,14 @@ class Edition(models.Model):
|
|||
except Identifier.DoesNotExist:
|
||||
return None
|
||||
|
||||
def add_author(self, author_name):
|
||||
if author_name:
|
||||
try:
|
||||
author= Author.objects.get(name=author_name)
|
||||
except Author.DoesNotExist:
|
||||
author= Author.objects.create(name=author_name)
|
||||
author.editions.add(self)
|
||||
|
||||
def set_publisher(self,publisher_name):
|
||||
if publisher_name and publisher_name != '':
|
||||
try:
|
||||
|
|
|
@ -559,10 +559,10 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
elif request.POST.has_key('add_subject_submit') and admin:
|
||||
new_subject = request.POST['add_subject'].strip()
|
||||
try:
|
||||
author= models.Subject.objects.get(name=new_subject)
|
||||
subject= models.Subject.objects.get(name=new_subject)
|
||||
except models.Subject.DoesNotExist:
|
||||
author=models.Subject.objects.create(name=new_subject)
|
||||
edition.new_subjects.append(new_subject)
|
||||
subject=models.Subject.objects.create(name=new_subject)
|
||||
edition.new_subjects.append(subject)
|
||||
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
|
||||
edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
|
||||
|
||||
|
@ -605,11 +605,7 @@ def new_edition(request, work_id, edition_id, by=None):
|
|||
else:
|
||||
models.Identifier.set(type=id_type, value=id_val, edition=edition, work=work)
|
||||
for author_name in edition.new_author_names:
|
||||
try:
|
||||
author= models.Author.objects.get(name=author_name)
|
||||
except models.Author.DoesNotExist:
|
||||
author=models.Author.objects.create(name=author_name)
|
||||
author.editions.add(edition)
|
||||
edition.add_author(author_name)
|
||||
for subject_name in edition.new_subjects:
|
||||
try:
|
||||
subject= models.Subject.objects.get(name=subject_name)
|
||||
|
|
Loading…
Reference in New Issue