Ignore:
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cyclope/models.py

    r139 r140  
    245245                                               object_id_field='self_id', 
    246246                                               content_type_field='self_type') 
    247  
    248     def delete(self, using=None): 
    249         # the cascade delete does not delete the RelatedContent elements 
    250         # where this object is the related content, so we do it here. 
    251         ctype = ContentType.objects.get_for_model(self) 
    252         related_from = RelatedContent.objects.filter(other_type=ctype, 
    253                                                     other_id=self.id) 
    254         for obj in related_from: 
    255             obj.delete() 
    256         super(BaseContent, self).delete(using) 
    257  
    258247    def pictures(self): 
    259248        if self.related_contents: 
  • cyclope/settings.py

    r139 r140  
    2626from django.conf import settings 
    2727from django.utils.translation import ugettext_lazy as _ 
    28 from django.db.models.signals import post_save 
     28from django.db.models.signals import post_save, pre_delete 
    2929 
    3030from cyclope.models import SiteSettings 
     
    110110 
    111111post_save.connect(_refresh_site_settings, sender=SiteSettings) 
     112 
     113from django.contrib.contenttypes.models import ContentType 
     114from cyclope.models import RelatedContent 
     115 
     116def _delete_related_contents(sender, instance, **kwargs): 
     117    # the cascade delete does not delete the RelatedContent elements 
     118    # where this object is the related content, so we do it here. 
     119    ctype = ContentType.objects.get_for_model(sender) 
     120    if hasattr(instance, 'id'): 
     121        print "instance:", instance.id 
     122        related_from = RelatedContent.objects.filter(other_type=ctype, 
     123                                                    other_id=instance.id) 
     124        for obj in related_from: 
     125            obj.delete() 
     126 
     127pre_delete.connect(_delete_related_contents) 
Note: See TracChangeset for help on using the changeset viewer.