├── .gitignore ├── .idea ├── .gitignore ├── django-rest-train.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── README.MD └── coreDrf ├── coreDrf ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── settings.cpython-310.pyc │ ├── urls.cpython-310.pyc │ └── wsgi.cpython-310.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── db.sqlite3 ├── img.png ├── manage.py ├── posts ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── admin.cpython-310.pyc │ ├── apps.cpython-310.pyc │ ├── models.cpython-310.pyc │ ├── serializers.cpython-310.pyc │ └── views.cpython-310.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-310.pyc │ │ └── __init__.cpython-310.pyc ├── models.py ├── serializers.py ├── tests.py └── views.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | 3 | 4 | .idea 5 | .vscode -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/django-rest-train.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 29 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Django rest framework train 2 | ![img.png](coreDrf/img.png) -------------------------------------------------------------------------------- /coreDrf/coreDrf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/coreDrf/__init__.py -------------------------------------------------------------------------------- /coreDrf/coreDrf/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/coreDrf/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/coreDrf/__pycache__/settings.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/coreDrf/__pycache__/settings.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/coreDrf/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/coreDrf/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/coreDrf/__pycache__/wsgi.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/coreDrf/__pycache__/wsgi.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/coreDrf/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for coreDrf project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coreDrf.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /coreDrf/coreDrf/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = 'django-insecure-!v@env93)&0^yw*k9eev7$(isj*q@9&)7kis97a!6@9es41!_!' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.admin', 23 | 'django.contrib.auth', 24 | 'django.contrib.contenttypes', 25 | 'django.contrib.sessions', 26 | 'django.contrib.messages', 27 | 'django.contrib.staticfiles', 28 | 'rest_framework', 29 | 30 | 'posts' 31 | ] 32 | 33 | MIDDLEWARE = [ 34 | 'django.middleware.security.SecurityMiddleware', 35 | 'django.contrib.sessions.middleware.SessionMiddleware', 36 | 'django.middleware.common.CommonMiddleware', 37 | 'django.middleware.csrf.CsrfViewMiddleware', 38 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 39 | 'django.contrib.messages.middleware.MessageMiddleware', 40 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 41 | ] 42 | 43 | ROOT_URLCONF = 'coreDrf.urls' 44 | 45 | TEMPLATES = [ 46 | { 47 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 48 | 'DIRS': [], 49 | 'APP_DIRS': True, 50 | 'OPTIONS': { 51 | 'context_processors': [ 52 | 'django.template.context_processors.debug', 53 | 'django.template.context_processors.request', 54 | 'django.contrib.auth.context_processors.auth', 55 | 'django.contrib.messages.context_processors.messages', 56 | ], 57 | }, 58 | }, 59 | ] 60 | 61 | WSGI_APPLICATION = 'coreDrf.wsgi.application' 62 | 63 | 64 | # Database 65 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 66 | 67 | DATABASES = { 68 | 'default': { 69 | 'ENGINE': 'django.db.backends.sqlite3', 70 | 'NAME': BASE_DIR / 'db.sqlite3', 71 | } 72 | } 73 | 74 | 75 | # Password validation 76 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 77 | 78 | AUTH_PASSWORD_VALIDATORS = [ 79 | { 80 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 81 | }, 82 | { 83 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 84 | }, 85 | { 86 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 87 | }, 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 90 | }, 91 | ] 92 | 93 | 94 | # Internationalization 95 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 96 | 97 | LANGUAGE_CODE = 'en-us' 98 | 99 | TIME_ZONE = 'UTC' 100 | 101 | USE_I18N = True 102 | 103 | USE_TZ = True 104 | 105 | 106 | # Static files (CSS, JavaScript, Images) 107 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 108 | 109 | STATIC_URL = 'static/' 110 | 111 | # Default primary key field type 112 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 113 | 114 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 115 | AUTH_USER_MODEL = 'posts.UserModel' 116 | REST_FRAMEWORK = { 117 | 'DEFAULT_PERMISSION_CLASSES': [ 118 | 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' 119 | ] 120 | } 121 | -------------------------------------------------------------------------------- /coreDrf/coreDrf/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import path, include 3 | from posts.views import PostView 4 | 5 | urlpatterns = [ 6 | path('admin/', admin.site.urls), 7 | path('api-auth/', include('rest_framework.urls')), 8 | path('api/data/', PostView.as_view()) 9 | ] 10 | -------------------------------------------------------------------------------- /coreDrf/coreDrf/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for coreDrf project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coreDrf.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /coreDrf/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/db.sqlite3 -------------------------------------------------------------------------------- /coreDrf/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/img.png -------------------------------------------------------------------------------- /coreDrf/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coreDrf.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /coreDrf/posts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__init__.py -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/admin.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/admin.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/apps.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/apps.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/models.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/models.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/serializers.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/serializers.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/__pycache__/views.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/__pycache__/views.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import * 3 | 4 | admin.site.register(UserModel) 5 | admin.site.register(Posts) 6 | 7 | -------------------------------------------------------------------------------- /coreDrf/posts/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PostsConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'posts' 7 | -------------------------------------------------------------------------------- /coreDrf/posts/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.4 on 2022-06-07 07:57 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | from django.db import migrations, models 6 | import django.utils.timezone 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ('auth', '0012_alter_user_first_name_max_length'), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='Posts', 20 | fields=[ 21 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('title', models.CharField(max_length=100)), 23 | ('post_id', models.IntegerField()), 24 | ('category', models.TextField(choices=[('Dj', 'Django'), ('Py', 'Python')], max_length=255)), 25 | ('start_date', models.DateTimeField(auto_now_add=True)), 26 | ('change_date', models.DateTimeField(auto_now_add=True)), 27 | ], 28 | ), 29 | migrations.CreateModel( 30 | name='UserModel', 31 | fields=[ 32 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 33 | ('password', models.CharField(max_length=128, verbose_name='password')), 34 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 35 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 36 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 37 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 38 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 39 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 40 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 41 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 42 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 43 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), 44 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), 45 | ], 46 | options={ 47 | 'verbose_name': 'user', 48 | 'verbose_name_plural': 'users', 49 | 'abstract': False, 50 | }, 51 | managers=[ 52 | ('objects', django.contrib.auth.models.UserManager()), 53 | ], 54 | ), 55 | ] 56 | -------------------------------------------------------------------------------- /coreDrf/posts/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/migrations/__init__.py -------------------------------------------------------------------------------- /coreDrf/posts/migrations/__pycache__/0001_initial.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/migrations/__pycache__/0001_initial.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/migrations/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/posts/migrations/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /coreDrf/posts/models.py: -------------------------------------------------------------------------------- 1 | from sre_constants import CATEGORY 2 | from django.db import models 3 | from django.contrib.auth.models import AbstractUser 4 | 5 | 6 | class UserModel(AbstractUser): 7 | pass 8 | 9 | 10 | CATEGORY_CHOICES = ( 11 | ('Dj', 'Django'), 12 | ('Py', 'Python') 13 | ) 14 | 15 | # create class model here 16 | class Posts(models.Model): 17 | title = models.CharField(max_length=100) 18 | post_id = models.IntegerField() 19 | category = models.TextField(max_length=255, choices=CATEGORY_CHOICES) 20 | start_date = models.DateTimeField(auto_now_add=True) 21 | change_date = models.DateTimeField(auto_now_add=True) 22 | 23 | def __str__(self): 24 | return self.title 25 | -------------------------------------------------------------------------------- /coreDrf/posts/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Posts 3 | 4 | 5 | class SerializerModel(serializers.ModelSerializer): 6 | class Meta: 7 | model = Posts 8 | fields = ( 9 | 'title', 10 | 'post_id', 11 | 'category', 12 | 'start_date', 13 | 'change_date' 14 | ) 15 | -------------------------------------------------------------------------------- /coreDrf/posts/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /coreDrf/posts/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from rest_framework.views import APIView 3 | from rest_framework.permissions import AllowAny 4 | from rest_framework.response import Response 5 | from .models import * 6 | from .serializers import SerializerModel 7 | 8 | 9 | class PostView(APIView): 10 | permission_classes = (AllowAny, ) 11 | 12 | def get(self, request, *args, **kwargs): 13 | post = Posts.objects.all() 14 | serializer = SerializerModel(post, many=True) 15 | return Response(serializer.data) 16 | 17 | -------------------------------------------------------------------------------- /coreDrf/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hwandev12/djang-rest-framework-train/0f8e447b22e4f932ee78724f5c73252b407dd1c6/coreDrf/requirements.txt --------------------------------------------------------------------------------