-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from iurwpoietknckvjndfsm-gndvkd/improvements
improvements in all apps
- Loading branch information
Showing
13 changed files
with
43 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import os | ||
|
||
from django.db.models.signals import pre_delete | ||
from django.db.models.signals import post_delete, pre_delete | ||
from django.dispatch import receiver | ||
|
||
from agriwise.plant_diseases.models import PlantDisease | ||
|
||
|
||
@receiver(pre_delete, sender=PlantDisease) | ||
def delete_image(sender, instance, **kwargs): | ||
def delete_media_image(sender, instance, **kwargs): | ||
# get the path of the image file | ||
file_path = instance.plant_image.image.path | ||
# delete the file if it exists | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
|
||
|
||
# used post_delete to avoid maximum recursion depth exceeded error when deleting related model instances | ||
@receiver(post_delete, sender=PlantDisease) | ||
def delete_plant_image(sender, instance, **kwargs): | ||
if instance.plant_image: | ||
instance.plant_image.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters