Add first models

master
Tom Darboux 7 months ago
parent 1ce03b7502
commit 0991d7f9bf
  1. 9
      README.md
  2. 0
      base/__init__.py
  3. 5
      base/admin.py
  4. 6
      base/apps.py
  5. 13
      base/models.py
  6. 25
      base/serializers.py
  7. 3
      base/tests.py
  8. 32
      base/views.py
  9. 3
      calendars/views.py
  10. 6
      requirements.txt
  11. 3
      simplestreetmap/settings.py
  12. 10
      simplestreetmap/urls.py

@ -1,6 +1,11 @@
# simplestreetmap-backend
# Simplestreetmap-backend
Backend for simplestreetmap.
- Display caldav event on the map
- Share maps with tokens
- Integrate external api like train api (sncf) to display journey on the map
- Integrate external api like train api (sncf) to display journey on the map
## Dependencies:
- **with sqlite backend:** GEOS, GDAL, PROJ, SpatiaLite
- **with postgresql backend:** GEOS, GDAL, PROJ, PostGIS

@ -0,0 +1,5 @@
from django.contrib import admin
from base.models import Layer, Place
# Register your models here.
admin.site.register(Layer)
admin.site.register(Place)

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

@ -0,0 +1,13 @@
#from django.db import models
from django.contrib.gis.db import models
# Create your models here.
class Layer(models.Model):
token = models.CharField(max_length=50)
class Place(models.Model):
lon = models.FloatField()
lat = models.FloatField()
name = models.CharField(max_length=50)
layer = models.ForeignKey(Layer, on_delete=models.CASCADE)

@ -0,0 +1,25 @@
from django.contrib.auth.models import User, Group
from rest_framework import serializers
from base.models import Layer, Place
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['url', 'username', 'email', 'groups']
class GroupSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Group
fields = ['url', 'name']
class PlaceSerializer(serializers.ModelSerializer):
class Meta:
model = Place
fields = '__all__'
class LayerSerializer(serializers.ModelSerializer):
places = PlaceSerializer(many=True, source='place_set')
class Meta:
model = Layer
fields = '__all__'

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

@ -0,0 +1,32 @@
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from base.serializers import UserSerializer, GroupSerializer, LayerSerializer
from base.models import Layer
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
class GroupViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Group.objects.all()
serializer_class = GroupSerializer
permission_classes = [permissions.IsAuthenticated]
class LayerViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Layer.objects.all()
serializer_class = LayerSerializer
permission_classes = [permissions.IsAuthenticated]

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

@ -0,0 +1,6 @@
asgiref==3.5.0
backports.zoneinfo==0.2.1
Django==4.0.4
djangorestframework==3.13.1
pytz==2022.1
sqlparse==0.4.2

@ -37,6 +37,9 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'django.contrib.gis',
'base'
]
MIDDLEWARE = [

@ -14,8 +14,16 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
from rest_framework import routers
from base import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'layers', views.LayerViewSet)
urlpatterns = [
path('', include(router.urls)),
path('admin/', admin.site.urls),
]

Loading…
Cancel
Save