Use leaflet for handling of locations in django admin

This commit is contained in:
Keannu Bernasol 2023-07-10 17:06:43 +08:00
parent 1fc262a530
commit 166d586fc2
15 changed files with 95 additions and 4 deletions

View file

@ -14,6 +14,7 @@ djangochannelsrestframework = "*"
daphne = "*" daphne = "*"
psycopg2 = "*" psycopg2 = "*"
gdal = {path = "./packages/GDAL-3.4.3-cp311-cp311-win_amd64.whl"} gdal = {path = "./packages/GDAL-3.4.3-cp311-cp311-win_amd64.whl"}
django-leaflet = "*"
[dev-packages] [dev-packages]

12
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "37bbd0140027c832ff7382532bd60c4def5a0a2a06d7fae418e89a7de6f109e1" "sha256": "efd1134f98df71c3c1209f70d5d962b6609fe23b044b57f80bba89db477b549f"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -268,6 +268,14 @@
"index": "pypi", "index": "pypi",
"version": "==4.2.3" "version": "==4.2.3"
}, },
"django-leaflet": {
"hashes": [
"sha256:2f6dc8c7187fd22e62b6f2b7b42eed86920f81bec312aa654981ebe5bc8e0866",
"sha256:ea35244539fe298156feafc7f1e2ce63067c8caa2ac6f8344069796b19d1ce9b"
],
"index": "pypi",
"version": "==0.29.0"
},
"django-templated-mail": { "django-templated-mail": {
"hashes": [ "hashes": [
"sha256:8db807effebb42a532622e2d142dfd453dafcd0d7794c4c3332acb90656315f9", "sha256:8db807effebb42a532622e2d142dfd453dafcd0d7794c4c3332acb90656315f9",
@ -311,7 +319,7 @@
"hashes": [ "hashes": [
"sha256:f78861fb5115d5c2f8cf3c52a492ff548da9e1256dc84088947379f90e77e5b6" "sha256:f78861fb5115d5c2f8cf3c52a492ff548da9e1256dc84088947379f90e77e5b6"
], ],
"path": "E:/Downloads/GDAL-3.4.3-cp311-cp311-win_amd64.whl", "path": "./packages/GDAL-3.4.3-cp311-cp311-win_amd64.whl",
"version": "==3.4.3" "version": "==3.4.3"
}, },
"hyperlink": { "hyperlink": {

View file

@ -9,5 +9,6 @@ urlpatterns = [
path('semesters/', include('semesters.urls')), path('semesters/', include('semesters.urls')),
path('subjects/', include('subjects.urls')), path('subjects/', include('subjects.urls')),
path('study_groups/', include('study_groups.urls')), path('study_groups/', include('study_groups.urls')),
path('messages/', include('studygroup_messages.urls')) path('messages/', include('studygroup_messages.urls')),
path('landmarks/', include('landmarks.urls')),
] ]

View file

@ -87,6 +87,8 @@ INSTALLED_APPS = [
'subjects', 'subjects',
'study_groups', 'study_groups',
'studygroup_messages', 'studygroup_messages',
'leaflet',
'landmarks',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -225,3 +227,11 @@ SITE_NAME = 'Stud-E'
JWT_TOKEN_LIFETIME = 10800 JWT_TOKEN_LIFETIME = 10800
ACCESS_TOKEN_LIFETIME = JWT_TOKEN_LIFETIME ACCESS_TOKEN_LIFETIME = JWT_TOKEN_LIFETIME
REFRESH_TOKEN_LIFETIME = 24 * JWT_TOKEN_LIFETIME REFRESH_TOKEN_LIFETIME = 24 * JWT_TOKEN_LIFETIME
LEAFLET_CONFIG = {
'DEFAULT_CENTER': (8.4803, 124.6498),
'DEFAULT_ZOOM': 24,
'MAX_ZOOM': 20,
'MIN_ZOOM': 3,
'SCALE': 'both'
}

View file

5
stude/landmarks/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin
from .models import Landmark
admin.site.register(Landmark, LeafletGeoAdmin)

6
stude/landmarks/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class LandmarksConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'landmarks'

View file

@ -0,0 +1,23 @@
# Generated by Django 4.2.3 on 2023-07-10 07:37
import django.contrib.gis.db.models.fields
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Landmark',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
('location', django.contrib.gis.db.models.fields.PolygonField(srid=4326)),
],
),
]

View file

11
stude/landmarks/models.py Normal file
View file

@ -0,0 +1,11 @@
from django.db import models
from django.contrib.gis.db import models as gis_models
# Create your models here.
class Landmark(models.Model):
name = models.CharField(max_length=64)
location = gis_models.PolygonField()
def __str__(self):
return self.name

View file

@ -0,0 +1,8 @@
from .models import Landmark
from rest_framework import serializers
class LandmarkSerializer(serializers.ModelSerializer):
class Meta:
model = Landmark
fields = '__all__'

3
stude/landmarks/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
stude/landmarks/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import path
from .views import LandmarkListView
urlpatterns = [
path('', LandmarkListView.as_view()),
]

8
stude/landmarks/views.py Normal file
View file

@ -0,0 +1,8 @@
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from .serializers import LandmarkSerializer
class LandmarkListView(generics.ListAPIView):
serializer_class = LandmarkSerializer
permission_classes = [IsAuthenticated]

View file

@ -1,4 +1,5 @@
from django.contrib import admin from django.contrib import admin
from .models import StudentStatus from .models import StudentStatus
from leaflet.admin import LeafletGeoAdmin
admin.site.register(StudentStatus) admin.site.register(StudentStatus, LeafletGeoAdmin)