fixed shape delete error

This commit is contained in:
Alexander-D-Karpov 2022-11-06 20:58:50 +03:00
parent 1bf80a75b5
commit e8669f4a1d
3 changed files with 17 additions and 2 deletions

View File

@ -173,7 +173,7 @@ class ListUpdateDicomImageNumberApi(GenericAPIView):
)
def put(self, request, dicom_slug):
dicom = get_object_or_404(Dicom, slug=dicom_slug)
[x.delete() for x in dicom.shapes]
dicom.delete_shapes()
serializer = BaseShapeLayerSerializer(
data=request.data, many=True, context={"request": request}
)

View File

@ -82,7 +82,15 @@ class Dicom(models.Model):
@property
def shapes(self):
return BaseShape.objects.filter(layer_fk__dicom=self)
qs = BaseShape.objects.filter(layer_fk__dicom=self)
if qs.exists():
return qs
return None
def delete_shapes(self):
shapes = self.shapes
if shapes:
[x.destroy() for x in shapes]
def get_layers(self):
return self.layers.filter(parent__isnull=True).first().serialize_self()

View File

@ -33,6 +33,12 @@ class BaseShape(PolymorphicModel):
def coordinates(self) -> [(int, int)]:
return self.shape_coordinates.all().values("x", "y")
def destroy(self):
try:
self.delete()
except BaseShape.DoesNotExist:
pass
def __str__(self):
return f"{self.TYPE} on {self.layer}"
@ -51,6 +57,7 @@ class Coordinate(models.Model):
class Circle(BaseShape):
TYPE = "circle"
radius = models.FloatField()
max_coordinates = 1