-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b16d38
commit e2c7f7e
Showing
12 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
'rest_framework', | ||
"corsheaders", | ||
'drf_yasg', | ||
'secondApp' | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SecondappConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'secondApp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |