From 48176ab935db4ccfd71d2128b9e020e4593a905d Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Wed, 2 Mar 2022 19:24:56 +0530 Subject: [PATCH] update --- rog/admin.py | 4 +- rog/choices.py | 2 + rog/mapping.py | 53 ++++++++++- rog/migrations/0003_auto_20220302_2240.py | 99 ++++++++++++++++++++ rog/models.py | 104 +++++++++++++++++++++- 5 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 rog/migrations/0003_auto_20220302_2240.py diff --git a/rog/admin.py b/rog/admin.py index fd52c73..ea55ed7 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 +from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): @@ -25,4 +25,6 @@ admin.site.register(Favorite, admin.ModelAdmin) admin.site.register(TravelList, admin.ModelAdmin) admin.site.register(TravelPoint, admin.ModelAdmin) admin.site.register(Event, admin.ModelAdmin) +admin.site.register(Location_line, LeafletGeoAdmin) +admin.site.register(Location_polygon, LeafletGeoAdmin) admin.site.register(ShapeLayers, admin.ModelAdmin) diff --git a/rog/choices.py b/rog/choices.py index 0b0e58a..7600f8a 100644 --- a/rog/choices.py +++ b/rog/choices.py @@ -2,4 +2,6 @@ from django.utils.translation import gettext_lazy as _ LAYER_CHOICES = ( (1, _("locations")), + (2, _("locations_line")), + (3, _("locations_polygon")), ) \ No newline at end of file diff --git a/rog/mapping.py b/rog/mapping.py index 65cfb2d..ef8c3e1 100644 --- a/rog/mapping.py +++ b/rog/mapping.py @@ -22,5 +22,56 @@ location_mapping = { 'remark':'remark', 'parammeters':'params', 'tags':'tags', - 'geom': 'MULTIPOLYGON', + 'geom': 'POINT', +} + +location_line_mapping = { + 'location_id' : 'loc_id', + 'location_name' : 'loc_name', + 'category': 'category', + 'zip':'zip', + 'address':'address', + 'prefecture':'prefecture', + 'area':'area', + 'city':'city', + 'photos':'photos', + 'videos':'videos', + 'webcontents':'webcontent', + 'status':'status', + 'portal':'portal', + 'group':'group', + 'phone':'phone', + 'fax':'fax', + 'email':'email', + 'facility':'facility', + 'remark':'remark', + 'parammeters':'params', + 'tags':'tags', + 'geom': 'LINESTRING', +} + + +location_polygon_mapping = { + 'location_id' : 'loc_id', + 'location_name' : 'loc_name', + 'category': 'category', + 'zip':'zip', + 'address':'address', + 'prefecture':'prefecture', + 'area':'area', + 'city':'city', + 'photos':'photos', + 'videos':'videos', + 'webcontents':'webcontent', + 'status':'status', + 'portal':'portal', + 'group':'group', + 'phone':'phone', + 'fax':'fax', + 'email':'email', + 'facility':'facility', + 'remark':'remark', + 'parammeters':'params', + 'tags':'tags', + 'geom': 'POLYGON', } \ No newline at end of file diff --git a/rog/migrations/0003_auto_20220302_2240.py b/rog/migrations/0003_auto_20220302_2240.py new file mode 100644 index 0000000..5c4bd9c --- /dev/null +++ b/rog/migrations/0003_auto_20220302_2240.py @@ -0,0 +1,99 @@ +# Generated by Django 3.2.9 on 2022-03-02 13:40 + +from django.conf import settings +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('rog', '0002_alter_location_location_id'), + ] + + operations = [ + migrations.AlterField( + model_name='location', + name='photos', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Phptos'), + ), + migrations.AlterField( + model_name='location', + name='videos', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Videos'), + ), + migrations.AlterField( + model_name='location', + name='webcontents', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Web Content'), + ), + migrations.AlterField( + model_name='shapelayers', + name='layerof', + field=models.IntegerField(choices=[(1, 'locations'), (2, 'locations_line'), (3, 'locations_polygon')], default=1), + ), + migrations.CreateModel( + name='Location_polygon', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('location_id', models.IntegerField(blank=True, null=True, verbose_name='Location id')), + ('location_name', models.CharField(max_length=255, verbose_name='Location Name')), + ('category', models.CharField(blank=True, max_length=255, null=True, verbose_name='Category')), + ('zip', models.CharField(blank=True, max_length=12, null=True, verbose_name='Zip code')), + ('address', models.CharField(blank=True, max_length=512, null=True, verbose_name='Address')), + ('prefecture', models.CharField(blank=True, max_length=255, null=True, verbose_name='Prefecture')), + ('area', models.CharField(blank=True, max_length=255, null=True, verbose_name='Area')), + ('city', models.CharField(blank=True, max_length=255, null=True, verbose_name='City')), + ('photos', models.CharField(blank=True, max_length=255, null=True, verbose_name='Phptos')), + ('videos', models.CharField(blank=True, max_length=255, null=True, verbose_name='Videos')), + ('webcontents', models.CharField(blank=True, max_length=255, null=True, verbose_name='Web Content')), + ('status', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('portal', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('group', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('phone', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('fax', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('email', models.EmailField(blank=True, max_length=255, null=True, verbose_name='Email')), + ('facility', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('remark', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('tags', models.CharField(blank=True, max_length=512, null=True, verbose_name='Tags')), + ('parammeters', models.CharField(blank=True, max_length=512, null=True, verbose_name='Parameters')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('last_updated_at', models.DateTimeField(auto_now=True)), + ('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)), + ('last_updated_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='location_polygon_updated_user', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Location_line', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('location_id', models.IntegerField(blank=True, null=True, verbose_name='Location id')), + ('location_name', models.CharField(max_length=255, verbose_name='Location Name')), + ('category', models.CharField(blank=True, max_length=255, null=True, verbose_name='Category')), + ('zip', models.CharField(blank=True, max_length=12, null=True, verbose_name='Zip code')), + ('address', models.CharField(blank=True, max_length=512, null=True, verbose_name='Address')), + ('prefecture', models.CharField(blank=True, max_length=255, null=True, verbose_name='Prefecture')), + ('area', models.CharField(blank=True, max_length=255, null=True, verbose_name='Area')), + ('city', models.CharField(blank=True, max_length=255, null=True, verbose_name='City')), + ('photos', models.CharField(blank=True, max_length=255, null=True, verbose_name='Phptos')), + ('videos', models.CharField(blank=True, max_length=255, null=True, verbose_name='Videos')), + ('webcontents', models.CharField(blank=True, max_length=255, null=True, verbose_name='Web Content')), + ('status', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('portal', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('group', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('phone', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('fax', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('email', models.EmailField(blank=True, max_length=255, null=True, verbose_name='Email')), + ('facility', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('remark', models.CharField(blank=True, max_length=255, null=True, verbose_name='Status')), + ('tags', models.CharField(blank=True, max_length=512, null=True, verbose_name='Tags')), + ('parammeters', models.CharField(blank=True, max_length=512, null=True, verbose_name='Parameters')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('last_updated_at', models.DateTimeField(auto_now=True)), + ('geom', django.contrib.gis.db.models.fields.MultiLineStringField(srid=4326)), + ('last_updated_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='location_line_updated_user', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/rog/models.py b/rog/models.py index 378300e..5521f90 100644 --- a/rog/models.py +++ b/rog/models.py @@ -11,7 +11,7 @@ import os, zipfile, glob import environ from geo.Postgres import Db from sqlalchemy.sql.functions import mode -from .mapping import location_mapping +from .mapping import location_mapping, location_line_mapping, location_polygon_mapping from .choices import LAYER_CHOICES from django.contrib.gis.utils import LayerMapping @@ -84,6 +84,100 @@ class Location(models.Model): return self.location_name +class Location(models.Model): + location_id=models.IntegerField(_('Location id'), blank=True, null=True) + location_name=models.CharField(_('Location Name'), max_length=255) + category=models.CharField(_('Category'), max_length=255, blank=True, null=True) + zip=models.CharField(_('Zip code'), max_length=12, blank=True, null=True) + address = models.CharField(_('Address'), max_length=512, blank=True, null=True) + prefecture = models.CharField(_('Prefecture'), max_length=255, blank=True, null=True) + area= models.CharField(_('Area'), max_length=255, blank=True, null=True) + city= models.CharField(_('City'), max_length=255, blank=True, null=True) + photos=models.CharField(_('Phptos'), max_length=255, blank=True, null=True) + videos=models.CharField(_('Videos'), max_length=255, blank=True, null=True) + webcontents=models.CharField(_('Web Content'), max_length=255, blank=True, null=True) + status=models.CharField(_('Status'),max_length=255, blank=True, null=True) + portal=models.CharField(_('Status'), max_length=255,blank=True, null=True) + group=models.CharField(_('Status'), max_length=255,blank=True, null=True) + phone=models.CharField(_('Status'), max_length=255,blank=True, null=True) + fax=models.CharField(_('Status'), max_length=255, blank=True, null=True) + email=models.EmailField(_('Email'), max_length=255,blank=True, null=True) + facility=models.CharField(_('Status'), max_length=255, blank=True, null=True) + remark=models.CharField(_('Status'), max_length=255, blank=True, null=True) + tags=models.CharField(_('Tags'), max_length=512, blank=True, null=True) + parammeters=models.CharField(_('Parameters'), max_length=512, blank=True, null=True) + created_at=models.DateTimeField(auto_now_add=True) + last_updated_user=models.ForeignKey(User, related_name="location_updated_user", on_delete=models.DO_NOTHING,blank=True, null=True) + last_updated_at=models.DateTimeField(auto_now=True) + geom=models.MultiPointField(srid=4326) + + def __str__(self): + return self.location_name + + +class Location_line(models.Model): + location_id=models.IntegerField(_('Location id'), blank=True, null=True) + location_name=models.CharField(_('Location Name'), max_length=255) + category=models.CharField(_('Category'), max_length=255, blank=True, null=True) + zip=models.CharField(_('Zip code'), max_length=12, blank=True, null=True) + address = models.CharField(_('Address'), max_length=512, blank=True, null=True) + prefecture = models.CharField(_('Prefecture'), max_length=255, blank=True, null=True) + area= models.CharField(_('Area'), max_length=255, blank=True, null=True) + city= models.CharField(_('City'), max_length=255, blank=True, null=True) + photos=models.CharField(_('Phptos'), max_length=255, blank=True, null=True) + videos=models.CharField(_('Videos'), max_length=255, blank=True, null=True) + webcontents=models.CharField(_('Web Content'), max_length=255, blank=True, null=True) + status=models.CharField(_('Status'),max_length=255, blank=True, null=True) + portal=models.CharField(_('Status'), max_length=255,blank=True, null=True) + group=models.CharField(_('Status'), max_length=255,blank=True, null=True) + phone=models.CharField(_('Status'), max_length=255,blank=True, null=True) + fax=models.CharField(_('Status'), max_length=255, blank=True, null=True) + email=models.EmailField(_('Email'), max_length=255,blank=True, null=True) + facility=models.CharField(_('Status'), max_length=255, blank=True, null=True) + remark=models.CharField(_('Status'), max_length=255, blank=True, null=True) + tags=models.CharField(_('Tags'), max_length=512, blank=True, null=True) + parammeters=models.CharField(_('Parameters'), max_length=512, blank=True, null=True) + created_at=models.DateTimeField(auto_now_add=True) + last_updated_user=models.ForeignKey(User, related_name="location_line_updated_user", on_delete=models.DO_NOTHING,blank=True, null=True) + last_updated_at=models.DateTimeField(auto_now=True) + geom=models.MultiLineStringField(srid=4326) + + def __str__(self): + return self.location_name + + +class Location_polygon(models.Model): + location_id=models.IntegerField(_('Location id'), blank=True, null=True) + location_name=models.CharField(_('Location Name'), max_length=255) + category=models.CharField(_('Category'), max_length=255, blank=True, null=True) + zip=models.CharField(_('Zip code'), max_length=12, blank=True, null=True) + address = models.CharField(_('Address'), max_length=512, blank=True, null=True) + prefecture = models.CharField(_('Prefecture'), max_length=255, blank=True, null=True) + area= models.CharField(_('Area'), max_length=255, blank=True, null=True) + city= models.CharField(_('City'), max_length=255, blank=True, null=True) + photos=models.CharField(_('Phptos'), max_length=255, blank=True, null=True) + videos=models.CharField(_('Videos'), max_length=255, blank=True, null=True) + webcontents=models.CharField(_('Web Content'), max_length=255, blank=True, null=True) + status=models.CharField(_('Status'),max_length=255, blank=True, null=True) + portal=models.CharField(_('Status'), max_length=255,blank=True, null=True) + group=models.CharField(_('Status'), max_length=255,blank=True, null=True) + phone=models.CharField(_('Status'), max_length=255,blank=True, null=True) + fax=models.CharField(_('Status'), max_length=255, blank=True, null=True) + email=models.EmailField(_('Email'), max_length=255,blank=True, null=True) + facility=models.CharField(_('Status'), max_length=255, blank=True, null=True) + remark=models.CharField(_('Status'), max_length=255, blank=True, null=True) + tags=models.CharField(_('Tags'), max_length=512, blank=True, null=True) + parammeters=models.CharField(_('Parameters'), max_length=512, blank=True, null=True) + created_at=models.DateTimeField(auto_now_add=True) + last_updated_user=models.ForeignKey(User, related_name="location_polygon_updated_user", on_delete=models.DO_NOTHING,blank=True, null=True) + last_updated_at=models.DateTimeField(auto_now=True) + geom=models.MultiPolygonField(srid=4326) + + def __str__(self): + return self.location_name + + + EVENT_STATUS = ( ("PREPARING", _("Preparing")), ("PROMOTION", _("Promotion")), @@ -224,10 +318,18 @@ class ShopRoute(models.Model): def getTableForModel(tbl): if tbl == 1: return Location.objects.model._meta.db_table; + elif tbl == 2: + return Location_line.objects.model._meta.db_table; + else: + return Location_polygon.objects.model._meta.db_table; def getMappingforModel(tbl, shp): if tbl == 1: return LayerMapping(Location, shp, location_mapping, transform=False) + elif tbl == 2: + return LayerMapping(Location_line, location_line_mapping, transform=False) + else: + return LayerMapping(Location_polygon, location_polygon_mapping, transform=False) class ShapeLayers(models.Model):