├── api ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── serializers.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-38.pyc │ │ └── __init__.cpython-38.pyc ├── models.py ├── serializers.py ├── tests.py ├── urls.py └── views.py ├── db.sqlite3 ├── manage.py ├── todo ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── migrations │ ├── __init__.py │ └── __pycache__ │ │ └── __init__.cpython-38.pyc ├── models.py ├── templates │ └── todo │ │ └── list.html ├── tests.py ├── urls.py └── views.py └── todo_drf ├── __init__.py ├── __pycache__ ├── __init__.cpython-38.pyc ├── settings.cpython-38.pyc ├── urls.cpython-38.pyc └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py /api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__init__.py -------------------------------------------------------------------------------- /api/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /api/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /api/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /api/__pycache__/serializers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/serializers.cpython-38.pyc -------------------------------------------------------------------------------- /api/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /api/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /api/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Task 3 | 4 | admin.site.register(Task) 5 | -------------------------------------------------------------------------------- /api/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ApiConfig(AppConfig): 5 | name = 'api' 6 | -------------------------------------------------------------------------------- /api/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-08-20 12:43 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='Task', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('title', models.CharField(max_length=200)), 19 | ('completed', models.BooleanField(blank=True, default=False, null=True)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /api/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/migrations/__init__.py -------------------------------------------------------------------------------- /api/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /api/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/api/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /api/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | class Task(models.Model): 5 | title = models.CharField(max_length=200) 6 | completed = models.BooleanField(default=False, blank=True, null=True) 7 | 8 | def __str__(self): 9 | return self.title 10 | -------------------------------------------------------------------------------- /api/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Task 3 | 4 | class TaskSerializer(serializers.ModelSerializer): 5 | class Meta(): 6 | model = Task 7 | fields = '__all__' 8 | 9 | -------------------------------------------------------------------------------- /api/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /api/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.apiIndex, name="api-index"), 6 | path('task-list/', views.taskList, name='task-list'), 7 | path('task-detail//', views.taskDetail, name='task-detail'), 8 | path('task-create/', views.taskCreate, name='task-create'), 9 | path('task-update//', views.taskUpdate, name='task-update'), 10 | path('task-delete//', views.taskDelete, name='task-delete'), 11 | ] 12 | -------------------------------------------------------------------------------- /api/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.http import JsonResponse 3 | from rest_framework.decorators import api_view 4 | from rest_framework.response import Response 5 | from .models import Task 6 | from .serializers import TaskSerializer 7 | 8 | @api_view(['GET']) 9 | def apiIndex(request): 10 | api_urls = { 11 | 'List': '/task-list/', 12 | 'Detail View': '/task-detail/', 13 | 'Create': '/task-create/', 14 | 'Update': '/task-update/', 15 | 'Delete': '/task-delete/', 16 | } 17 | return Response(api_urls) 18 | 19 | @api_view(['GET']) 20 | def taskList(request): 21 | tasks = Task.objects.all().order_by('-id') 22 | serializer = TaskSerializer(tasks, many=True) 23 | return Response(serializer.data) 24 | 25 | @api_view(['GET']) 26 | def taskDetail(request, pk): 27 | tasks = Task.objects.get(id=pk) 28 | serializer = TaskSerializer(tasks, many=False) 29 | return Response(serializer.data) 30 | 31 | @api_view(['POST']) 32 | def taskCreate(request): 33 | serializer = TaskSerializer(data=request.data) 34 | 35 | if serializer.is_valid(): 36 | serializer.save() 37 | 38 | return Response(serializer.data) 39 | 40 | @api_view(['POST']) 41 | def taskUpdate(request, pk): 42 | task = Task.objects.get(id=pk) 43 | serializer = TaskSerializer(instance=task, data=request.data) 44 | 45 | if serializer.is_valid(): 46 | serializer.save() 47 | 48 | return Response(serializer.data) 49 | 50 | @api_view(['DELETE']) 51 | def taskDelete(request, pk): 52 | task = Task.objects.get(id=pk) 53 | task.delete() 54 | return Response("Item deleted") 55 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/db.sqlite3 -------------------------------------------------------------------------------- /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 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_drf.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /todo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__init__.py -------------------------------------------------------------------------------- /todo/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /todo/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /todo/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /todo/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /todo/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /todo/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /todo/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class TodoConfig(AppConfig): 5 | name = 'todo' 6 | -------------------------------------------------------------------------------- /todo/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/migrations/__init__.py -------------------------------------------------------------------------------- /todo/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /todo/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /todo/templates/todo/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | TO DO 6 | 7 | 8 | 9 | 54 | 55 | 56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 |
64 |
65 | 66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /todo/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /todo/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.index, name="index"), 6 | ] 7 | -------------------------------------------------------------------------------- /todo/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | def index(request): 4 | return render(request, 'todo/list.html') 5 | -------------------------------------------------------------------------------- /todo_drf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo_drf/__init__.py -------------------------------------------------------------------------------- /todo_drf/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo_drf/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /todo_drf/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo_drf/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /todo_drf/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo_drf/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /todo_drf/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkshaon/todo_django_rest_framework_with_ajax/0ea74339de977386efd973cf6c11667efea6af92/todo_drf/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /todo_drf/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for todo_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/3.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', 'todo_drf.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /todo_drf/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for todo_drf project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'dq%=98%7po^g_h=*prt7l_6bm+8ef*_p3t!m+lowsi*k00x)7p' 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 | 'api', 41 | 'rest_framework', 42 | 'todo', 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | ] 54 | 55 | ROOT_URLCONF = 'todo_drf.urls' 56 | 57 | TEMPLATES = [ 58 | { 59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 60 | 'DIRS': [], 61 | 'APP_DIRS': True, 62 | 'OPTIONS': { 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'todo_drf.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_L10N = True 116 | 117 | USE_TZ = True 118 | 119 | 120 | # Static files (CSS, JavaScript, Images) 121 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 122 | 123 | STATIC_URL = '/static/' 124 | -------------------------------------------------------------------------------- /todo_drf/urls.py: -------------------------------------------------------------------------------- 1 | """todo_drf URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('api/', include('api.urls')), 22 | path('', include('todo.urls')), 23 | # path('', include('api.urls')), 24 | ] 25 | -------------------------------------------------------------------------------- /todo_drf/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for todo_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/3.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', 'todo_drf.settings') 15 | 16 | application = get_wsgi_application() 17 | --------------------------------------------------------------------------------