diff --git a/rog/admin.py b/rog/admin.py index 2799aac..d3d3b1a 100644 --- a/rog/admin.py +++ b/rog/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from leaflet.admin import LeafletGeoAdmin from leaflet.admin import LeafletGeoAdminMixin from leaflet_admin_list.admin import LeafletAdminListMixin -from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks +from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks, ShapeFileLocations from django.contrib.auth.admin import UserAdmin class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): @@ -50,5 +50,6 @@ admin.site.register(UserTracks, LeafletGeoAdmin); admin.site.register(GifuAreas, LeafletGeoAdmin) admin.site.register(JpnSubPerf, LeafletGeoAdmin) admin.site.register(ShapeLayers, admin.ModelAdmin) +#admin.site.register(ShapeFileLocations, admin.ModelAdmin) -admin.site.register(CustomUser, UserAdminConfig) \ No newline at end of file +admin.site.register(CustomUser, UserAdminConfig) diff --git a/rog/migrations/0016_shapefilelocations.py b/rog/migrations/0016_shapefilelocations.py new file mode 100644 index 0000000..74d131f --- /dev/null +++ b/rog/migrations/0016_shapefilelocations.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.9 on 2022-06-21 09:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rog', '0015_auto_20220619_1611'), + ] + + operations = [ + migrations.CreateModel( + name='ShapeFileLocations', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('shapefile', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Shapelayer')), + ('locid', models.IntegerField(blank=True, null=True)), + ], + ), + ] diff --git a/rog/models.py b/rog/models.py index 45d4e8e..8561c18 100644 --- a/rog/models.py +++ b/rog/models.py @@ -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])))