diff --git a/django/requirements.txt b/django/requirements.txt index ffaf623c..04354701 100644 Binary files a/django/requirements.txt and b/django/requirements.txt differ diff --git a/django/tamprog/garden/migrations/0003_fertilizer_name.py b/django/tamprog/garden/migrations/0003_fertilizer_name.py new file mode 100644 index 00000000..209c1981 --- /dev/null +++ b/django/tamprog/garden/migrations/0003_fertilizer_name.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.16 on 2024-10-16 10:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('garden', '0002_remove_plant_fertilizer_id_order_fertilizer_id'), + ] + + operations = [ + migrations.AddField( + model_name='fertilizer', + name='name', + field=models.CharField(default=1, max_length=1024), + preserve_default=False, + ), + ] diff --git a/django/tamprog/garden/models.py b/django/tamprog/garden/models.py index 9e17a331..1558b1ea 100644 --- a/django/tamprog/garden/models.py +++ b/django/tamprog/garden/models.py @@ -27,7 +27,8 @@ class GardenBed(models.Model): size = models.FloatField() class Fertilizer(models.Model): - #состав + #название,состав + name = models.CharField(max_length=1024) compound = models.CharField(max_length=1024) class User(models.Model): diff --git a/django/tamprog/garden/urls.py b/django/tamprog/garden/urls.py index fc004173..2519b8b4 100644 --- a/django/tamprog/garden/urls.py +++ b/django/tamprog/garden/urls.py @@ -1,9 +1,26 @@ -#from django.urls import path from django.urls import path, include from rest_framework import routers from .views import * +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi +from django.conf import settings +from django.conf.urls.static import static + +schema_view = get_schema_view( + openapi.Info( + title="Your Project API", + default_version='v1', + description="Electronic agronomist", + terms_of_service="https://www.google.com/policies/terms/", + contact=openapi.Contact(email="zarembiczkiy@mail.ru"), + license=openapi.License(name="BSD License"), + ), + public=True, + permission_classes=(permissions.AllowAny,), +) router_agronomist = routers.SimpleRouter() router_agronomist.register(r'agronomist', AgronomistViewSet) @@ -43,4 +60,6 @@ path('', include(router_plant.urls)), path('', include(router_plot.urls)), path('', include(router_order.urls)), -] \ No newline at end of file + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), +] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \ No newline at end of file diff --git a/django/tamprog/tamprog/settings.py b/django/tamprog/tamprog/settings.py index 2eb84ee4..f3d19054 100644 --- a/django/tamprog/tamprog/settings.py +++ b/django/tamprog/tamprog/settings.py @@ -13,6 +13,7 @@ import os from pathlib import Path from dotenv import load_dotenv +import re # Load environment variables from .env file load_dotenv() @@ -45,9 +46,11 @@ 'rest_framework', 'garden', 'drf_yasg', + 'corsheaders', ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -57,6 +60,30 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +CORS_ORIGIN_ALLOW_ALL = True + +CORS_ALLOW_ALL_ORIGINS = True + +CORS_ALLOW_CREDENTIALS = True + +CORS_ALLOW_HEADERS = \ + ['Access-Control-Allow-Origin', + 'Access-Control-Allow-Credentials', + 'headers', + 'content-type', + 'x-csrftoken',] + +CORS_ALLOW_METHODS = ['GET', 'POST', 'PUT', + 'DELETE', 'OPTIONS', 'PATCH', 'UPDATE', 'DESTROY'] + +#CORS_ALLOWED_ORIGIN_REGEXES = [ +# r'^https?://homelab.kerasi.ru$', # основной фронт +# r'^https?://homelab.kerasi.ru/api/v1/.*$', # API +# r'^https?://homelab.kerasi.ru/api/swagger/.*$', # Swagger +# r'^https?://homelab.kerasi.ru/redis-commander/.*$', # Redis Commander +# r'^https?://homelab.kerasi.ru/rabbitmq/.*$', # RabbitMQ +#] + ROOT_URLCONF = 'tamprog.urls' TEMPLATES = [ @@ -147,3 +174,8 @@ # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', + 'PAGE_SIZE': 30 +} \ No newline at end of file diff --git a/django/tamprog/tamprog/urls.py b/django/tamprog/tamprog/urls.py index 627ae36d..f7be4ec4 100644 --- a/django/tamprog/tamprog/urls.py +++ b/django/tamprog/tamprog/urls.py @@ -18,29 +18,9 @@ from django.urls import path, include from rest_framework import routers from django.views.generic import RedirectView -from rest_framework import permissions -from drf_yasg.views import get_schema_view -from drf_yasg import openapi -from django.conf import settings -from django.conf.urls.static import static - -schema_view = get_schema_view( - openapi.Info( - title="Your Project API", - default_version='v1', - description="Electronic agronomist", - terms_of_service="https://www.google.com/policies/terms/", - contact=openapi.Contact(email="zarembiczkiy@mail.ru"), - license=openapi.License(name="BSD License"), - ), - public=True, - permission_classes=(permissions.AllowAny,), -) urlpatterns = [ path('admin/', admin.site.urls), path('log/', include('rest_framework.urls')), path('api/v1/', include('garden.urls')), - path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), -] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +]