Changeset 138:3bf7566e6d80
- Timestamp:
- 03/08/10 18:18:00 (3 years ago)
- Branch:
- default
- Files:
-
- 3 edited
-
cyclope/models.py (modified) (1 diff)
-
cyclope/settings.py (modified) (2 diffs)
-
demo/cyclope_project/db/site.db (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
cyclope/models.py
r124 r138 245 245 object_id_field='self_id', 246 246 content_type_field='self_type') 247 248 def delete(self, using=None):249 # the cascade delete does not delete the RelatedContent elements250 # 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 258 247 def pictures(self): 259 248 if self.related_contents: -
cyclope/settings.py
r126 r138 26 26 from django.conf import settings 27 27 from django.utils.translation import ugettext_lazy as _ 28 from django.db.models.signals import post_save 28 from django.db.models.signals import post_save, pre_delete 29 29 30 30 from cyclope.models import SiteSettings … … 107 107 108 108 post_save.connect(_refresh_site_settings, sender=SiteSettings) 109 110 from django.contrib.contenttypes.models import ContentType 111 from cyclope.models import RelatedContent 112 113 def _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 124 pre_delete.connect(_delete_related_contents)
Note: See TracChangeset
for help on using the changeset viewer.

