mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-28 16:25:44 +08:00
Use leaflet for handling of locations in django admin
This commit is contained in:
parent
1fc262a530
commit
166d586fc2
15 changed files with 95 additions and 4 deletions
0
stude/landmarks/__init__.py
Normal file
0
stude/landmarks/__init__.py
Normal file
5
stude/landmarks/admin.py
Normal file
5
stude/landmarks/admin.py
Normal 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
6
stude/landmarks/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LandmarksConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'landmarks'
|
23
stude/landmarks/migrations/0001_initial.py
Normal file
23
stude/landmarks/migrations/0001_initial.py
Normal 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)),
|
||||
],
|
||||
),
|
||||
]
|
0
stude/landmarks/migrations/__init__.py
Normal file
0
stude/landmarks/migrations/__init__.py
Normal file
11
stude/landmarks/models.py
Normal file
11
stude/landmarks/models.py
Normal 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
|
8
stude/landmarks/serializers.py
Normal file
8
stude/landmarks/serializers.py
Normal 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
3
stude/landmarks/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
6
stude/landmarks/urls.py
Normal file
6
stude/landmarks/urls.py
Normal 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
8
stude/landmarks/views.py
Normal 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]
|
Loading…
Add table
Add a link
Reference in a new issue