Updated migrations, added swagger

This commit is contained in:
stepan323446 2025-11-21 11:50:54 +01:00
parent a6fb473f09
commit 180b71c0f0
7 changed files with 86 additions and 4 deletions

3
.env.example Normal file
View File

@ -0,0 +1,3 @@
SECRET_KEY=
ENVIRONMENT=
MIKRO_SECRET_KEY=

View File

@ -40,9 +40,17 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'django_filters',
'drf_spectacular',
'weather.apps.WeatherConfig'
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@ -54,6 +62,25 @@ MIDDLEWARE = [
ROOT_URLCONF = 'project.urls'
SPECTACULAR_SETTINGS = {
'TITLE': 'Weather Mikro API',
'DESCRIPTION': 'Weather stats by weather',
'VERSION': '1.0.0',
'COMPONENT_SPLIT_REQUEST': True
}
CORS_ALLOW_ALL_ORIGINS = True
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 20,
'DEFAULT_AUTHENTICATION_CLASSES': [
],
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',

View File

@ -14,9 +14,16 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('api/', include([
# path('', include('weather.urls')),
])),
]

16
requirements.txt Normal file
View File

@ -0,0 +1,16 @@
asgiref==3.11.0
attrs==25.4.0
Django==5.2.8
django-filter==25.2
django-rest-framework==0.1.0
djangorestframework==3.16.1
drf-spectacular==0.29.0
inflection==0.5.1
jsonschema==4.25.1
jsonschema-specifications==2025.9.1
python-dotenv==1.2.1
PyYAML==6.0.3
referencing==0.37.0
rpds-py==0.29.0
sqlparse==0.5.3
uritemplate==4.2.0

View File

@ -0,0 +1,25 @@
# Generated by Django 5.2.8 on 2025-11-21 10:39
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='WeatherStats',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('humidityAir', models.FloatField(default=0)),
('humidityGround', models.FloatField(default=0)),
('temperature', models.FloatField(default=0)),
('light', models.FloatField(default=0)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
]

View File

@ -2,7 +2,11 @@ from django.db import models
# Create your models here.
class WeatherStats(models.Model):
humidity = models.FloatField(default=0)
humidityAir = models.FloatField(default=0)
humidityGround = models.FloatField(default=0)
temperature = models.FloatField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
light = models.FloatField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return 'Weather data by ' + self.created_at

0
weather/urls.py Normal file
View File