diff --git a/backend/backend/__pycache__/settings.cpython-312.pyc b/backend/backend/__pycache__/settings.cpython-312.pyc index eb2a4a3..48406be 100644 Binary files a/backend/backend/__pycache__/settings.cpython-312.pyc and b/backend/backend/__pycache__/settings.cpython-312.pyc differ diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 7f2d95a..6a67afd 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -46,6 +46,7 @@ 'rest_framework', "corsheaders", 'drf_yasg', + 'secondApp' ] MIDDLEWARE = [ diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 08e0a9f..f4521aa 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -24,11 +24,19 @@ from django.contrib import admin from django.urls import path, include, re_path from app.views import * +from secondApp.views import * +from rest_framework.routers import DefaultRouter from drf_yasg.views import get_schema_view from drf_yasg import openapi +router = DefaultRouter() +router.register(r'/hayvan', HayvanOlustur) + + + + schema_view = get_schema_view( openapi.Info( title="CoderMungan Portfolio Api", @@ -49,4 +57,9 @@ path('api/', include('app.urls')), path('docs/', 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'), + path('animal',include(router.urls)), + path('hayvanpost/', HayvanSinglePost.as_view()), + path('hayvanguncelle/', HayvanSadeceGuncelle.as_view()), + path('hayvangetistegi/',HayvanSadeceGet.as_view()), + path('hayvanfiltre', HayvanFiltre.as_view()), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/backend/secondApp/__init__.py b/backend/secondApp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/secondApp/admin.py b/backend/secondApp/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/secondApp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/secondApp/apps.py b/backend/secondApp/apps.py new file mode 100644 index 0000000..1de166f --- /dev/null +++ b/backend/secondApp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SecondappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'secondApp' diff --git a/backend/secondApp/migrations/0001_initial.py b/backend/secondApp/migrations/0001_initial.py new file mode 100644 index 0000000..41ea9f6 --- /dev/null +++ b/backend/secondApp/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.7 on 2023-12-09 23:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Animal', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='Name Animal')), + ('width', models.IntegerField(verbose_name='Animal Width')), + ('height', models.IntegerField(verbose_name='Animal Height')), + ('tur', models.CharField(max_length=50)), + ('yas', models.IntegerField()), + ('renk', models.CharField(blank=True, max_length=50, null=True)), + ('olusturulma_tarihi', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/backend/secondApp/migrations/__init__.py b/backend/secondApp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/secondApp/models.py b/backend/secondApp/models.py new file mode 100644 index 0000000..3db0a20 --- /dev/null +++ b/backend/secondApp/models.py @@ -0,0 +1,18 @@ +from django.db import models + +# Create your models here. + + + +class Animal(models.Model): + name = models.CharField(("Name Animal"), max_length=50) + width = models.IntegerField(("Animal Width")) + height = models.IntegerField(("Animal Height")) + tur = models.CharField(max_length=50) + yas = models.IntegerField() + renk = models.CharField(max_length=50, blank=True, null=True) + olusturulma_tarihi = models.DateTimeField(auto_now_add=True) + + + def __str__(self) -> str: + return self.name \ No newline at end of file diff --git a/backend/secondApp/serializers.py b/backend/secondApp/serializers.py new file mode 100644 index 0000000..74b9cd0 --- /dev/null +++ b/backend/secondApp/serializers.py @@ -0,0 +1,14 @@ +from rest_framework.serializers import ModelSerializer +from rest_framework import serializers + +from .models import * + + + +class AnimalSerializer(serializers.ModelSerializer): + + class Meta: + model = Animal + fields = "__all__" + + diff --git a/backend/secondApp/tests.py b/backend/secondApp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/secondApp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/secondApp/views.py b/backend/secondApp/views.py new file mode 100644 index 0000000..bb27984 --- /dev/null +++ b/backend/secondApp/views.py @@ -0,0 +1,60 @@ +from django.shortcuts import render + +from rest_framework import status +from rest_framework.response import Response + +# ModelViewSet Import +from rest_framework import viewsets +from rest_framework import generics +from rest_framework.decorators import APIView +from rest_framework.permissions import IsAuthenticatedOrReadOnly +# Modeli Çek +from .models import * + +# Serializer Çek +from .serializers import * +# Create your views here. + +# Model Geniş Model +class HayvanOlustur(viewsets.ModelViewSet): + queryset = Animal.objects.all() + serializer_class = AnimalSerializer + + +# Retrive olduğundan dolayı tekli veriyi güncelleme +class HayvanSadeceGuncelle(generics.RetrieveUpdateDestroyAPIView): + lookup_field = 'id' + queryset=Animal.objects.all() + serializer_class = AnimalSerializer + + +# Retrive olduğundan dolayı tekli veriyi gösterme +class HayvanSadeceGet(generics.RetrieveAPIView): + lookup_field = 'id' + queryset = Animal.objects.all() + serializer_class = AnimalSerializer + + +# Retrive olduğundan dolayı tekli veriyi silme +class HayvanSinglePost(generics.RetrieveDestroyAPIView): + lookup_field = 'id' + queryset = Animal.objects.all() + serializer_class = AnimalSerializer + + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + self.perform_destroy(instance) + + + data = {'message': 'İt silindi'} + + return Response(data, status=status.HTTP_201_CREATED) + + +# Filtreleme işlemleri +class HayvanFiltre(generics.ListAPIView): + queryset = Animal.objects.all() + serializer_class = AnimalSerializer + + def get_queryset(self): + return Animal.objects.filter(yas__lte = 50) \ No newline at end of file