mirror of
https://github.com/leaders-of-digital-9-task/backend.git
synced 2024-11-28 04:03:43 +03:00
fixed shape delete error
This commit is contained in:
parent
1bf80a75b5
commit
e8669f4a1d
|
@ -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}
|
||||
)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user