mirror of
https://github.com/Llloooggg/WhereToGo.git
synced 2026-03-06 04:36:22 +03:00
Базовая карта
This commit is contained in:
0
wheretogo/maps/__init__.py
Normal file
0
wheretogo/maps/__init__.py
Normal file
5
wheretogo/maps/admin.py
Normal file
5
wheretogo/maps/admin.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from maps.models import Facility
|
||||
|
||||
admin.site.register(Facility)
|
||||
8
wheretogo/maps/api.py
Normal file
8
wheretogo/maps/api.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rest_framework import routers
|
||||
|
||||
from maps.viewsets import FacilityViewSet
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r"facilities", FacilityViewSet)
|
||||
|
||||
urlpatterns = router.urls
|
||||
7
wheretogo/maps/apps.py
Normal file
7
wheretogo/maps/apps.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MapConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "maps"
|
||||
verbose_name = "Maps"
|
||||
29
wheretogo/maps/migrations/0001_initial.py
Normal file
29
wheretogo/maps/migrations/0001_initial.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 4.0.3 on 2022-04-21 11:59
|
||||
|
||||
import django.contrib.gis.db.models.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Facility',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('address', models.CharField(max_length=100)),
|
||||
('city', models.CharField(max_length=50)),
|
||||
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'facility',
|
||||
'verbose_name_plural': 'Facilities',
|
||||
},
|
||||
),
|
||||
]
|
||||
0
wheretogo/maps/migrations/__init__.py
Normal file
0
wheretogo/maps/migrations/__init__.py
Normal file
19
wheretogo/maps/models.py
Normal file
19
wheretogo/maps/models.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.contrib.gis.db import models as gis_models
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Facility(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
address = models.CharField(max_length=100)
|
||||
city = models.CharField(max_length=50)
|
||||
location = gis_models.PointField(
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "facility"
|
||||
verbose_name_plural = "Facilities"
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
11
wheretogo/maps/serializers.py
Normal file
11
wheretogo/maps/serializers.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from rest_framework_gis import serializers
|
||||
|
||||
from maps.models import Facility
|
||||
|
||||
|
||||
class FacilitySerializer(serializers.GeoFeatureModelSerializer):
|
||||
class Meta:
|
||||
|
||||
fields = ("id", "name", "address", "city")
|
||||
geo_field = "location"
|
||||
model = Facility
|
||||
3
wheretogo/maps/tests.py
Normal file
3
wheretogo/maps/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
8
wheretogo/maps/urls.py
Normal file
8
wheretogo/maps/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
from maps.views import MapView
|
||||
|
||||
app_name = "maps"
|
||||
|
||||
urlpatterns = [
|
||||
path("map/", MapView.as_view(), name="map"),
|
||||
]
|
||||
6
wheretogo/maps/views.py
Normal file
6
wheretogo/maps/views.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
|
||||
class MapView(TemplateView):
|
||||
|
||||
template_name = "maps/map.html"
|
||||
13
wheretogo/maps/viewsets.py
Normal file
13
wheretogo/maps/viewsets.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework_gis import filters
|
||||
|
||||
from maps.models import Facility
|
||||
from maps.serializers import FacilitySerializer
|
||||
|
||||
|
||||
class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
|
||||
bbox_filter_field = "location"
|
||||
filter_backends = (filters.InBBoxFilter,)
|
||||
queryset = Facility.objects.all()
|
||||
serializer_class = FacilitySerializer
|
||||
Reference in New Issue
Block a user