pertama kali
This commit is contained in:
commit
94b1926cdd
0
freekake_api/content/__init__.py
Normal file
0
freekake_api/content/__init__.py
Normal file
BIN
freekake_api/content/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
freekake_api/content/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/content/__pycache__/admin.cpython-312.pyc
Normal file
BIN
freekake_api/content/__pycache__/admin.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/content/__pycache__/apps.cpython-312.pyc
Normal file
BIN
freekake_api/content/__pycache__/apps.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/content/__pycache__/models.cpython-312.pyc
Normal file
BIN
freekake_api/content/__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
3
freekake_api/content/admin.py
Normal file
3
freekake_api/content/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
freekake_api/content/apps.py
Normal file
6
freekake_api/content/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ContentConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'content'
|
||||
0
freekake_api/content/migrations/__init__.py
Normal file
0
freekake_api/content/migrations/__init__.py
Normal file
Binary file not shown.
3
freekake_api/content/models.py
Normal file
3
freekake_api/content/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
freekake_api/content/tests.py
Normal file
3
freekake_api/content/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
freekake_api/content/views.py
Normal file
3
freekake_api/content/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
0
freekake_api/core/__init__.py
Normal file
0
freekake_api/core/__init__.py
Normal file
BIN
freekake_api/core/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/admin.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/admin.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/apps.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/apps.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/models.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/serializers.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/serializers.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/urls.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/urls.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/core/__pycache__/views.cpython-312.pyc
Normal file
BIN
freekake_api/core/__pycache__/views.cpython-312.pyc
Normal file
Binary file not shown.
3
freekake_api/core/admin.py
Normal file
3
freekake_api/core/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
freekake_api/core/apps.py
Normal file
6
freekake_api/core/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'core'
|
||||
50
freekake_api/core/migrations/0001_initial.py
Normal file
50
freekake_api/core/migrations/0001_initial.py
Normal file
@ -0,0 +1,50 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-10 02:47
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Province',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=2)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='RegencyCity',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=4)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('province', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.province')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='District',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=6)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('regency_city', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.regencycity')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Village',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=10)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('district', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.district')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
freekake_api/core/migrations/__init__.py
Normal file
0
freekake_api/core/migrations/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
32
freekake_api/core/models.py
Normal file
32
freekake_api/core/models.py
Normal file
@ -0,0 +1,32 @@
|
||||
from django.db import models
|
||||
|
||||
class Province(models.Model):
|
||||
code = models.CharField(max_length=2, null=False)
|
||||
name = models.CharField(max_length=255, null=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class RegencyCity(models.Model):
|
||||
code = models.CharField(max_length=4, null=False)
|
||||
name = models.CharField(max_length=255, null=False)
|
||||
province = models.ForeignKey(Province, on_delete=models.CASCADE, null=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class District(models.Model):
|
||||
code = models.CharField(max_length=6, null=False)
|
||||
name = models.CharField(max_length=255, null=False)
|
||||
regency_city = models.ForeignKey(RegencyCity, on_delete=models.CASCADE, null=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Village(models.Model):
|
||||
code = models.CharField(max_length=10, null=False)
|
||||
name = models.CharField(max_length=255, null=False)
|
||||
district = models.ForeignKey(District, on_delete=models.CASCADE, null=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
42
freekake_api/core/serializers.py
Normal file
42
freekake_api/core/serializers.py
Normal file
@ -0,0 +1,42 @@
|
||||
from rest_framework import serializers
|
||||
from core import models
|
||||
|
||||
class ProvinceSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = models.Province
|
||||
fields = ['id', 'code', 'name']
|
||||
|
||||
class RegencyCitySerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = models.RegencyCity
|
||||
fields = ['id', 'code', 'name', 'province']
|
||||
|
||||
class RegencyCityDetailSerializer(serializers.ModelSerializer):
|
||||
province = ProvinceSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = models.RegencyCity
|
||||
fields = ['id', 'code', 'name', 'province']
|
||||
|
||||
class DistrictSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = models.District
|
||||
fields = ['id', 'code', 'name', 'regency_city']
|
||||
|
||||
|
||||
class DistrictDetailSerializer(serializers.ModelSerializer):
|
||||
regency_city = RegencyCityDetailSerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.District
|
||||
fields = ['id', 'code', 'name', 'regency_city']
|
||||
|
||||
class VillageSerializer(serializers.ModelSerializer):
|
||||
district = DistrictSerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.Village
|
||||
fields = ['id', 'code', 'name', 'district']
|
||||
3
freekake_api/core/tests.py
Normal file
3
freekake_api/core/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
16
freekake_api/core/urls.py
Normal file
16
freekake_api/core/urls.py
Normal file
@ -0,0 +1,16 @@
|
||||
from django.urls import path
|
||||
from rest_framework.urlpatterns import format_suffix_patterns
|
||||
from core import views
|
||||
|
||||
urlpatterns = [
|
||||
path('provinces/', views.ProvinceList.as_view()),
|
||||
path('provinces/<int:pk>/', views.ProvinceDetail.as_view()),
|
||||
|
||||
path('regencies_cities/', views.RegencyCityList.as_view()),
|
||||
path('regencies_cities/<int:pk>/', views.RegencyCityDetail.as_view()),
|
||||
|
||||
path('districts/', views.DistrictList.as_view()),
|
||||
path('districts/<int:pk>/', views.DistrictDetail.as_view()),
|
||||
]
|
||||
|
||||
urlpatterns = format_suffix_patterns(urlpatterns)
|
||||
75
freekake_api/core/views.py
Normal file
75
freekake_api/core/views.py
Normal file
@ -0,0 +1,75 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import generics
|
||||
|
||||
from core import models, serializers
|
||||
|
||||
# PROVINCES
|
||||
|
||||
class ProvinceList(generics.ListCreateAPIView):
|
||||
queryset = models.Province.objects.all()
|
||||
serializer_class = serializers.ProvinceSerializer
|
||||
search_fields = ['name', 'code']
|
||||
filterset_fields = ['name', 'code']
|
||||
ordering_fields = '__all__'
|
||||
|
||||
class ProvinceDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = models.Province.objects.all()
|
||||
serializer_class = serializers.ProvinceSerializer
|
||||
|
||||
# REGENCY/CITY
|
||||
|
||||
class RegencyCityList(generics.ListCreateAPIView):
|
||||
queryset = models.RegencyCity.objects.all()
|
||||
serializer_class = serializers.RegencyCitySerializer
|
||||
search_fields = ['name', 'code']
|
||||
filterset_fields = ['name', 'code']
|
||||
ordering_fields = '__all__'
|
||||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = self.serializer_class
|
||||
|
||||
if self.request.method == 'GET':
|
||||
serializer_class = serializers.RegencyCityDetailSerializer
|
||||
|
||||
return serializer_class
|
||||
|
||||
class RegencyCityDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = models.RegencyCity.objects.all()
|
||||
serializer_class = serializers.RegencyCitySerializer
|
||||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = self.serializer_class
|
||||
|
||||
if self.request.method == 'GET':
|
||||
serializer_class = serializers.RegencyCityDetailSerializer
|
||||
|
||||
return serializer_class
|
||||
|
||||
# DISTRICT
|
||||
|
||||
class DistrictList(generics.ListCreateAPIView):
|
||||
queryset = models.District.objects.all()
|
||||
serializer_class = serializers.DistrictSerializer
|
||||
search_fields = ['name', 'code']
|
||||
filterset_fields = ['name', 'code']
|
||||
ordering_fields = '__all__'
|
||||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = self.serializer_class
|
||||
|
||||
if self.request.method == 'GET':
|
||||
serializer_class = serializers.DistrictDetailSerializer
|
||||
|
||||
return serializer_class
|
||||
|
||||
class DistrictDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = models.District.objects.all()
|
||||
serializer_class = serializers.DistrictSerializer
|
||||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = self.serializer_class
|
||||
|
||||
if self.request.method == 'GET':
|
||||
serializer_class = serializers.DistrictDetailSerializer
|
||||
|
||||
return serializer_class
|
||||
0
freekake_api/db.sqlite3
Normal file
0
freekake_api/db.sqlite3
Normal file
0
freekake_api/freekake_api/__init__.py
Normal file
0
freekake_api/freekake_api/__init__.py
Normal file
BIN
freekake_api/freekake_api/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
freekake_api/freekake_api/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/freekake_api/__pycache__/settings.cpython-312.pyc
Normal file
BIN
freekake_api/freekake_api/__pycache__/settings.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/freekake_api/__pycache__/urls.cpython-312.pyc
Normal file
BIN
freekake_api/freekake_api/__pycache__/urls.cpython-312.pyc
Normal file
Binary file not shown.
BIN
freekake_api/freekake_api/__pycache__/wsgi.cpython-312.pyc
Normal file
BIN
freekake_api/freekake_api/__pycache__/wsgi.cpython-312.pyc
Normal file
Binary file not shown.
16
freekake_api/freekake_api/asgi.py
Normal file
16
freekake_api/freekake_api/asgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for freekake_api project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'freekake_api.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
133
freekake_api/freekake_api/settings.py
Normal file
133
freekake_api/freekake_api/settings.py
Normal file
@ -0,0 +1,133 @@
|
||||
"""
|
||||
Django settings for freekake_api project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.1.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.1/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-@wf_1z20edr655upw6t3tf==56!t%vk(oky=v4+n0io+om=4^x'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'rest_framework',
|
||||
'psycopg2',
|
||||
|
||||
'core',
|
||||
'content',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'freekake_api.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'freekake_api.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'freekake_app_db',
|
||||
'USER': 'postgres',
|
||||
'PASSWORD': 'asalada123',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
24
freekake_api/freekake_api/urls.py
Normal file
24
freekake_api/freekake_api/urls.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""
|
||||
URL configuration for freekake_api project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.1/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
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 django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
# path('admin/', admin.site.urls),
|
||||
|
||||
path('core/', include('core.urls')),
|
||||
]
|
||||
16
freekake_api/freekake_api/wsgi.py
Normal file
16
freekake_api/freekake_api/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for freekake_api project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'freekake_api.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
22
freekake_api/manage.py
Executable file
22
freekake_api/manage.py
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'freekake_api.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user