first commit
This commit is contained in:
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
22
utils/admin.py
Normal file
22
utils/admin.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
|
||||
|
||||
from .models import JsonToType
|
||||
|
||||
|
||||
@admin.register(JsonToType)
|
||||
class JsonToTypeAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'id',
|
||||
'user',
|
||||
'title',
|
||||
'json_data',
|
||||
'type_data',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'is_active',
|
||||
)
|
||||
list_filter = ('user', 'created_at', 'updated_at', 'is_active')
|
||||
date_hierarchy = 'created_at'
|
||||
6
utils/apps.py
Normal file
6
utils/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UtilsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'utils'
|
||||
36
utils/migrations/0001_initial.py
Normal file
36
utils/migrations/0001_initial.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-24 19:48
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='JsonToType',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=254, verbose_name='Başlık')),
|
||||
('json_data', models.JSONField(verbose_name='Json Veri')),
|
||||
('type_data', models.TextField(verbose_name='Type Veri')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Oluşturulma Tarihi')),
|
||||
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Güncelleme Tarihi')),
|
||||
('is_active', models.BooleanField(choices=[(True, 'Evet'), (False, 'Hayır')], default=False, verbose_name='Yayındamı')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='json_to_type_user', to=settings.AUTH_USER_MODEL, verbose_name='Kullanıcı')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Json To Type',
|
||||
'verbose_name_plural': 'Json To Type',
|
||||
'db_table': 'json_to_type',
|
||||
'ordering': ['-updated_at'],
|
||||
},
|
||||
),
|
||||
]
|
||||
18
utils/migrations/0002_alter_jsontotype_json_data.py
Normal file
18
utils/migrations/0002_alter_jsontotype_json_data.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-24 20:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('utils', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='jsontotype',
|
||||
name='json_data',
|
||||
field=models.JSONField(unique=True, verbose_name='Json Veri'),
|
||||
),
|
||||
]
|
||||
18
utils/migrations/0003_alter_jsontotype_type_data.py
Normal file
18
utils/migrations/0003_alter_jsontotype_type_data.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-24 20:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('utils', '0002_alter_jsontotype_json_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='jsontotype',
|
||||
name='type_data',
|
||||
field=models.TextField(unique=True, verbose_name='Type Veri'),
|
||||
),
|
||||
]
|
||||
0
utils/migrations/__init__.py
Normal file
0
utils/migrations/__init__.py
Normal file
26
utils/models.py
Normal file
26
utils/models.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class JsonToType(models.Model):
|
||||
aktif = (
|
||||
(True, 'Evet'),
|
||||
(False, 'Hayır'),
|
||||
)
|
||||
user = models.ForeignKey('accounts.CustomUser', on_delete=models.CASCADE, related_name='json_to_type_user',
|
||||
verbose_name="Kullanıcı")
|
||||
title = models.CharField(max_length=254, verbose_name="Başlık")
|
||||
json_data = models.JSONField(verbose_name="Json Veri", unique=True)
|
||||
type_data = models.TextField(verbose_name="Type Veri", unique=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Oluşturulma Tarihi")
|
||||
updated_at = models.DateTimeField(auto_now=True, editable=False, verbose_name="Güncelleme Tarihi")
|
||||
is_active = models.BooleanField(default=False, verbose_name='Yayındamı', choices=aktif)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-updated_at"]
|
||||
db_table = 'json_to_type'
|
||||
verbose_name_plural = "Json To Type"
|
||||
verbose_name = "Json To Type"
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
10
utils/serializers.py
Normal file
10
utils/serializers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from utils.models import JsonToType
|
||||
|
||||
|
||||
class JsonToTypeSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = JsonToType
|
||||
fields = ['id', 'title', 'json_data', 'type_data', 'created_at', 'updated_at','is_active']
|
||||
3
utils/tests.py
Normal file
3
utils/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
utils/urls.py
Normal file
7
utils/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path, include
|
||||
|
||||
from utils.views import JsonToTypeListCreate
|
||||
|
||||
urlpatterns = [
|
||||
path('utils/jasontotype/', JsonToTypeListCreate.as_view(), name='jasontotype'),
|
||||
]
|
||||
18
utils/views.py
Normal file
18
utils/views.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.generics import ListCreateAPIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from utils.models import JsonToType
|
||||
from utils.serializers import JsonToTypeSerializer
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class JsonToTypeListCreate(ListCreateAPIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = JsonToTypeSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return JsonToType.objects.filter(user=self.request.user, is_active=True).order_by('-updated_at')
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(user=self.request.user)
|
||||
Reference in New Issue
Block a user