Changeset 138:3bf7566e6d80


Ignore:
Timestamp:
03/08/10 18:18:00 (3 years ago)
Author:
nicoechaniz <nico@…>
Branch:
default
Message:

fixed related content deletion from change_list action

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cyclope/models.py

    r124 r138  
    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

    r126 r138  
    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 
     
    107107 
    108108post_save.connect(_refresh_site_settings, sender=SiteSettings) 
     109 
     110from django.contrib.contenttypes.models import ContentType 
     111from cyclope.models import RelatedContent 
     112 
     113def _delete_related_contents(sender, instance, **kwargs): 
     114    # the cascade delete does not delete the RelatedContent elements 
     115    # where this object is the related content, so we do it here. 
     116    ctype = ContentType.objects.get_for_model(sender) 
     117    if hasattr(instance, 'id'): 
     118        print "instance:", instance.id 
     119        related_from = RelatedContent.objects.filter(other_type=ctype, 
     120                                                    other_id=instance.id) 
     121        for obj in related_from: 
     122            obj.delete() 
     123 
     124pre_delete.connect(_delete_related_contents) 
Note: See TracChangeset for help on using the changeset viewer.