├── README.md ├── db.sqlite3 ├── drf ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── settings.cpython-39.pyc │ ├── urls.cpython-39.pyc │ └── wsgi.cpython-39.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── manage.py ├── posts ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ ├── models.cpython-39.pyc │ ├── serializers.cpython-39.pyc │ └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-39.pyc │ │ └── __init__.cpython-39.pyc ├── models.py ├── serializers.py ├── tests.py └── views.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # DRF Beginner Course -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/db.sqlite3 -------------------------------------------------------------------------------- /drf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/drf/__init__.py -------------------------------------------------------------------------------- /drf/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/drf/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /drf/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/drf/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /drf/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/drf/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /drf/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/drf/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /drf/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for drf 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', 'drf.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /drf/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for drf project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.4. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-g%a^ewu!0@8pbz3b7y%&%7)_%+_5tax8n4yfp6_%v8_98@z*+*' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 41 | 'rest_framework', 42 | 43 | 'posts' 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'drf.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'drf.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': BASE_DIR / 'db.sqlite3', 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 90 | 91 | AUTH_PASSWORD_VALIDATORS = [ 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 103 | }, 104 | ] 105 | 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_TZ = True 117 | 118 | 119 | # Static files (CSS, JavaScript, Images) 120 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 121 | 122 | STATIC_URL = 'static/' 123 | 124 | # Default primary key field type 125 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 126 | 127 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 128 | 129 | REST_FRAMEWORK = { 130 | 'DEFAULT_PERMISSION_CLASSES': [ 131 | 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' 132 | ] 133 | } -------------------------------------------------------------------------------- /drf/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/posts/', PostView.as_view()) 9 | ] 10 | -------------------------------------------------------------------------------- /drf/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for drf 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', 'drf.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /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', 'drf.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 | -------------------------------------------------------------------------------- /posts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__init__.py -------------------------------------------------------------------------------- /posts/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /posts/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /posts/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /posts/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /posts/__pycache__/serializers.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/serializers.cpython-39.pyc -------------------------------------------------------------------------------- /posts/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /posts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | admin.site.register(Post) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /posts/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.4 on 2022-06-05 23:06 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Post', 16 | fields=[ 17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('title', models.CharField(max_length=255)), 19 | ('post_id', models.IntegerField()), 20 | ('categoriya', models.TextField(choices=[('Dj', 'Django'), ('Py', 'Python')], max_length=255)), 21 | ('start_sanasi', models.DateTimeField(auto_now_add=True)), 22 | ('ozgartirilgan_sanasi', models.DateTimeField(auto_now_add=True)), 23 | ], 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /posts/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/migrations/__init__.py -------------------------------------------------------------------------------- /posts/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /posts/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/posts/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /posts/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | CATEGORIYA_TANLOVI = ( 4 | ('Dj', 'Django'), 5 | ('Py', 'Python') 6 | ) 7 | 8 | # Create your models here. 9 | class Post(models.Model): 10 | title = models.CharField(max_length=255) 11 | post_id = models.IntegerField() 12 | categoriya = models.TextField(max_length=255, choices=CATEGORIYA_TANLOVI) 13 | start_sanasi = models.DateTimeField(auto_now_add=True) 14 | ozgartirilgan_sanasi = models.DateTimeField(auto_now_add=True) 15 | 16 | def __str__(self): 17 | return self.title 18 | -------------------------------------------------------------------------------- /posts/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Post 3 | 4 | 5 | class PostSerializer(serializers.ModelSerializer): 6 | class Meta: 7 | model = Post 8 | fields = ( 9 | 'title', 10 | 'post_id', 11 | 'categoriya', 12 | 'start_sanasi', 13 | 'ozgartirilgan_sanasi' 14 | ) -------------------------------------------------------------------------------- /posts/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /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 Post 6 | from .serializers import PostSerializer 7 | # Create your views here. 8 | 9 | class PostView(APIView): 10 | permission_classes = (AllowAny,) 11 | 12 | def get(self, request, *args, **kwargs): 13 | post = Post.objects.all() 14 | serializer = PostSerializer(post, many=True) 15 | return Response(serializer.data) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/python019/drf-beginner-course/323b0092733e859a02768ea746c80fadfc5ef048/requirements.txt --------------------------------------------------------------------------------