update for location layer delete
This commit is contained in:
@ -452,6 +452,10 @@ class ShapeLayers(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class ShapeFileLocations(models.Model):
|
||||
shapefile=models.CharField(_('Shapelayer'), max_length=2048 ,blank=True, null=True)
|
||||
locid=models.IntegerField(blank=True, null=True)
|
||||
|
||||
|
||||
def remove_bom_inplace(path):
|
||||
"""Removes BOM mark, if it exists, from a file and rewrites it in-place"""
|
||||
@ -499,6 +503,17 @@ def my_callback(sender, instance, *args, **kwargs):
|
||||
def deletePrevious(mdl, fields):
|
||||
with transaction.atomic():
|
||||
mdl.objects.filter(location_id = int(fields[0])).delete();
|
||||
|
||||
|
||||
@receiver(post_delete,sender=ShapeLayers)
|
||||
def deleteShapelocation(sender,instance,*args,**kwargs):
|
||||
locids = ShapeFileLocations.objects.filter(shapefile=instance.name).values_list('locid')
|
||||
print("------- name----")
|
||||
print(locids)
|
||||
print("------- name----")
|
||||
Location.objects.filter(location_id__in=locids).delete()
|
||||
ShapeFileLocations.objects.filter(shapefile=instance.name).delete()
|
||||
|
||||
|
||||
|
||||
@receiver(post_save, sender=ShapeLayers)
|
||||
@ -549,6 +564,7 @@ def publish_data(sender, instance, created, **kwargs):
|
||||
print(fields[0])
|
||||
print("@@@@@@@@@@@@")
|
||||
if instance.layerof == 1:
|
||||
insertShapeLayerLocation(instance.name, fields)
|
||||
updateLocation(mdl, fields)
|
||||
if instance.layerof == 2:
|
||||
updateLineTable(mdl, fields)
|
||||
@ -559,6 +575,12 @@ def publish_data(sender, instance, created, **kwargs):
|
||||
print('##################',e)
|
||||
|
||||
|
||||
def insertShapeLayerLocation(name, fields):
|
||||
sll = ShapeFileLocations(shapefile=name, locid=fields[0])
|
||||
sll.save();
|
||||
|
||||
|
||||
|
||||
def updateLocation(mdl, fields):
|
||||
print(f"Updating {fields[0]} - {fields[1]}")
|
||||
print(mdl.objects.filter(location_id = int(fields[0])))
|
||||
|
||||
Reference in New Issue
Block a user