You've already forked WhereToGoRedux
mirror of
https://github.com/Llloooggg/WhereToGoRedux.git
synced 2026-03-06 04:56:23 +03:00
init
This commit is contained in:
0
backend/wheretogo/facilities/__init__.py
Normal file
0
backend/wheretogo/facilities/__init__.py
Normal file
13
backend/wheretogo/facilities/admin.py
Normal file
13
backend/wheretogo/facilities/admin.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.contrib.gis.db import models
|
||||
from django.forms.widgets import Textarea
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
from facilities.models import Facility
|
||||
|
||||
|
||||
class FacilityAdmin(admin.ModelAdmin):
|
||||
formfield_overrides = {models.PointField: {"widget": Textarea}}
|
||||
|
||||
|
||||
admin.site.register(Facility, FacilityAdmin)
|
||||
8
backend/wheretogo/facilities/apps.py
Normal file
8
backend/wheretogo/facilities/apps.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class FacilitiesConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "facilities"
|
||||
verbose_name = _("Facilities")
|
||||
41
backend/wheretogo/facilities/migrations/0001_initial.py
Normal file
41
backend/wheretogo/facilities/migrations/0001_initial.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Generated by Django 4.1.1 on 2022-09-09 23:29
|
||||
|
||||
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
backend/wheretogo/facilities/migrations/__init__.py
Normal file
0
backend/wheretogo/facilities/migrations/__init__.py
Normal file
20
backend/wheretogo/facilities/models.py
Normal file
20
backend/wheretogo/facilities/models.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.contrib.gis.db import models as gis_models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
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 __str__(self):
|
||||
return f"{self.name}: {self.city}, {self.address}"
|
||||
10
backend/wheretogo/facilities/serializers.py
Normal file
10
backend/wheretogo/facilities/serializers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from rest_framework_gis import serializers
|
||||
|
||||
from facilities.models import Facility
|
||||
|
||||
|
||||
class FacilitySerializer(serializers.GeoFeatureModelSerializer):
|
||||
class Meta:
|
||||
model = Facility
|
||||
fields = ("id", "name", "address", "city")
|
||||
geo_field = "location"
|
||||
3
backend/wheretogo/facilities/tests.py
Normal file
3
backend/wheretogo/facilities/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
11
backend/wheretogo/facilities/urls.py
Normal file
11
backend/wheretogo/facilities/urls.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from rest_framework import routers
|
||||
|
||||
from facilities.viewsets import FacilityViewSet
|
||||
|
||||
app_name = "facilities"
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register("facilities", FacilityViewSet, "facilities")
|
||||
|
||||
urlpatterns = router.urls
|
||||
3
backend/wheretogo/facilities/views.py
Normal file
3
backend/wheretogo/facilities/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
13
backend/wheretogo/facilities/viewsets.py
Normal file
13
backend/wheretogo/facilities/viewsets.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework_gis import filters
|
||||
|
||||
from facilities.models import Facility
|
||||
from facilities.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