deleting works should delete attached objects
I think the only place this should get invoked is via adminpull/91/head
parent
2f9dda8432
commit
604260363f
|
@ -597,7 +597,7 @@ def merge_works(w1, w2, user=None):
|
||||||
for work_relation in w2.works_related_from.all():
|
for work_relation in w2.works_related_from.all():
|
||||||
work_relation.from_work = w1
|
work_relation.from_work = w1
|
||||||
work_relation.save()
|
work_relation.save()
|
||||||
w2.delete()
|
w2.delete(cascade=False)
|
||||||
return w1
|
return w1
|
||||||
|
|
||||||
def detach_edition(e):
|
def detach_edition(e):
|
||||||
|
|
|
@ -22,6 +22,8 @@ from django.db.models import F
|
||||||
from django.db.models.signals import post_save, pre_delete
|
from django.db.models.signals import post_save, pre_delete
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
from django_comments.models import Comment
|
||||||
|
|
||||||
import regluit
|
import regluit
|
||||||
from regluit.marc.models import MARCRecord as NewMARC
|
from regluit.marc.models import MARCRecord as NewMARC
|
||||||
from questionnaire.models import Landing
|
from questionnaire.models import Landing
|
||||||
|
@ -131,13 +133,39 @@ class Work(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['title']
|
ordering = ['title']
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._last_campaign = None
|
self._last_campaign = None
|
||||||
super(Work, self).__init__(*args, **kwargs)
|
super(Work, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def delete(self, *args, **kwargs):
|
||||||
|
if kwargs.get('cascade', True):
|
||||||
|
if self.offers.all() or self.claim.all() or self.campaigns.all() or self.acqs.all() \
|
||||||
|
or self.holds.all() or self.landings.all():
|
||||||
|
return
|
||||||
|
for wishlist in self.wishlists.all():
|
||||||
|
wishlist.remove_work(self)
|
||||||
|
for userprofile in self.contributors.all():
|
||||||
|
userprofile.works.remove(self)
|
||||||
|
for identifier in self.identifiers.all():
|
||||||
|
identifier.delete()
|
||||||
|
for comment in Comment.objects.for_model(self):
|
||||||
|
comment.delete()
|
||||||
|
for edition in self.editions.all():
|
||||||
|
for ebook in edition.ebooks.all():
|
||||||
|
ebook.delete()
|
||||||
|
for ebookfile in edition.ebook_files.all():
|
||||||
|
ebookfile.delete()
|
||||||
|
edition.delete()
|
||||||
|
for work_relation in self.works_related_to.all():
|
||||||
|
work_relation.delete()
|
||||||
|
for work_relation in self.works_related_from.all():
|
||||||
|
work_relation.delete()
|
||||||
|
super(Work, self).delete(*args, **kwargs) # Call the "real" save() method.
|
||||||
|
|
||||||
def id_for(self, type):
|
def id_for(self, type):
|
||||||
return id_for(self, type)
|
return id_for(self, type)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue