Skip to content

Commit

Permalink
13845 fix device type image save (#13851)
Browse files Browse the repository at this point in the history
* 13845 check original image is null in save

* 13845 update delete image code
  • Loading branch information
arthanson authored Sep 25, 2023
1 parent 04796a6 commit 0ce2b1b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions netbox/dcim/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import cached_property

from django.core.exceptions import ValidationError
from django.core.files.storage import default_storage
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models import F, ProtectedError
Expand Down Expand Up @@ -332,10 +333,10 @@ def save(self, *args, **kwargs):
ret = super().save(*args, **kwargs)

# Delete any previously uploaded image files that are no longer in use
if self.front_image != self._original_front_image:
self._original_front_image.delete(save=False)
if self.rear_image != self._original_rear_image:
self._original_rear_image.delete(save=False)
if self._original_front_image and self.front_image != self._original_front_image:
default_storage.delete(self._original_front_image)
if self._original_rear_image and self.rear_image != self._original_rear_image:
default_storage.delete(self._original_rear_image)

return ret

Expand Down

0 comments on commit 0ce2b1b

Please sign in to comment.