Re: Admin - delete with removing FK objects
I made what I wanted using signals:) All works now. I use post delete to be sure that object is deleted, than I remove images. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EcDKuOgfY-oJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Admin - delete with removing FK objects
14.9.2011 2:52, galgal kirjoitti: I have 2 models class Article(models.Model): active = models.BooleanField(default=False, db_index=True) title = models.CharField(max_length=150) class ArticleGallery(models.Model): article = models.ForeignKey(Article) image = models.ImageField(upload_to=settings.ARTICLE_GALLERY_IMG_UPLOAD_TO) def delete(self, *args, **kwargs): self.image.delete() super(ArticleGallery, self).delete(*args, **kwargs) But when i click delete in Article and submit it, elements are removed from database but ArticleGallery.delete() isn't fired up. I need the delete method to be run when deleting Article. Any clues? This is "known" behavior of Django admin. For efficiency reasons Django uses queryset delete method which does not call delete() method. You can though write your own delete hook in admin to traverse through all instances. But be aware that approach you're using has it's caveats: what if deletion stops at some point? You have deleted images from the disk but database _will_ be rolled back thus leaving you with records without images. -- Jani Tiainen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Admin - delete with removing FK objects
I have 2 models class Article(models.Model): active = models.BooleanField(default=False, db_index=True) title = models.CharField(max_length=150) class ArticleGallery(models.Model): article = models.ForeignKey(Article) image = models.ImageField(upload_to=settings.ARTICLE_GALLERY_IMG_UPLOAD_TO) def delete(self, *args, **kwargs): self.image.delete() super(ArticleGallery, self).delete(*args, **kwargs) But when i click delete in Article and submit it, elements are removed from database but ArticleGallery.delete() isn't fired up. I need the delete method to be run when deleting Article. Any clues? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/TIPI-hi3_d0J. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.