├── README.md ├── db.sqlite3 ├── employeeapi ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── admin.cpython-37.pyc │ ├── models.cpython-37.pyc │ ├── serializers.cpython-37.pyc │ └── viewsets.cpython-37.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-37.pyc │ │ └── __init__.cpython-37.pyc ├── models.py ├── serializers.py ├── tests.py ├── views.py └── viewsets.py ├── manage.py └── restfulapicrud ├── __init__.py ├── __pycache__ ├── __init__.cpython-37.pyc ├── router.cpython-37.pyc ├── settings.cpython-37.pyc ├── urls.cpython-37.pyc └── wsgi.cpython-37.pyc ├── router.py ├── settings.py ├── urls.py └── wsgi.py /README.md: -------------------------------------------------------------------------------- 1 | # Django-Restful-API-CRUD-Operations- 2 | Django Restful API CRUD Operations with PostgreSQL using Web Methods GET, POST, PUT and DELETE 3 | 4 | ## Get the Code 5 | 6 | ``` 7 | $ git clone https://github.com/CodAffection/Django-Restful-API-CRUD-Operations-.git 8 | ``` 9 | 10 | ## How it works ? 11 | 12 | :tv: Video tutorial on this same topic 13 | Url : https://youtu.be/1k0fRG098cU 14 | 15 | Video Tutorial for Django Restful API CRUD Operations with Postgres 18 | 19 | 20 | | :bar_chart: | List of Tutorials | | :moneybag: | Support Us | 21 | |--------------------------:|:---------------------|---|---------------------:|:-------------------------------------| 22 | | Angular |http://bit.ly/2KQN9xF | |Paypal | https://goo.gl/bPcyXW | 23 | | Asp.Net Core |http://bit.ly/30fPDMg | |Amazon Affiliate | https://geni.us/JDzpE | 24 | | React |http://bit.ly/325temF | | 25 | | Python |http://bit.ly/2ws4utg | | :point_right: | Follow Us | 26 | | Node.js |https://goo.gl/viJcFs | |Website |http://www.codaffection.com | 27 | | Asp.Net MVC |https://goo.gl/gvjUJ7 | |YouTube |https://www.youtube.com/codaffection | 28 | | Flutter |https://bit.ly/3ggmmJz| |Facebook |https://www.facebook.com/codaffection | 29 | | Web API |https://goo.gl/itVayJ | |Twitter |https://twitter.com/CodAffection | 30 | | MEAN Stack |https://goo.gl/YJPPAH | | 31 | | C# Tutorial |https://goo.gl/s1zJxo | | 32 | | Asp.Net WebForm |https://goo.gl/GXC2aJ | | 33 | | C# WinForm |https://goo.gl/vHS9Hd | | 34 | | MS SQL |https://goo.gl/MLYS9e | | 35 | | Crystal Report |https://goo.gl/5Vou7t | | 36 | | CG Exercises in C Program |https://goo.gl/qEWJCs | | 37 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/db.sqlite3 -------------------------------------------------------------------------------- /employeeapi/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__init__.py -------------------------------------------------------------------------------- /employeeapi/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/__pycache__/serializers.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__pycache__/serializers.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/__pycache__/viewsets.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/__pycache__/viewsets.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /employeeapi/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class EmployeeapiConfig(AppConfig): 5 | name = 'employeeapi' 6 | -------------------------------------------------------------------------------- /employeeapi/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.2.7 on 2019-11-12 06:19 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='Employee', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('fullname', models.CharField(max_length=100)), 19 | ('emp_code', models.CharField(max_length=3)), 20 | ('mobile', models.CharField(max_length=15)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /employeeapi/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/migrations/__init__.py -------------------------------------------------------------------------------- /employeeapi/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/employeeapi/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /employeeapi/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | class Employee(models.Model): 6 | fullname = models.CharField(max_length=100) 7 | emp_code = models.CharField(max_length=3) 8 | mobile = models.CharField(max_length=15) 9 | 10 | # Create / Insert / Add - POST 11 | # Retrieve / Fetch - GET 12 | # Update / Edit - PUT 13 | # Delete / Remove - DELETE 14 | -------------------------------------------------------------------------------- /employeeapi/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Employee 3 | 4 | class EmployeeSerializer(serializers.ModelSerializer): 5 | class Meta: 6 | model =Employee 7 | fields = '__all__' -------------------------------------------------------------------------------- /employeeapi/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /employeeapi/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /employeeapi/viewsets.py: -------------------------------------------------------------------------------- 1 | from rest_framework import viewsets 2 | from . import models 3 | from . import serializers 4 | 5 | class EmployeeViewset(viewsets.ModelViewSet): 6 | queryset = models.Employee.objects.all() 7 | serializer_class = serializers.EmployeeSerializer -------------------------------------------------------------------------------- /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', 'restfulapicrud.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 | -------------------------------------------------------------------------------- /restfulapicrud/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__init__.py -------------------------------------------------------------------------------- /restfulapicrud/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /restfulapicrud/__pycache__/router.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__pycache__/router.cpython-37.pyc -------------------------------------------------------------------------------- /restfulapicrud/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /restfulapicrud/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /restfulapicrud/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodAffection/Django-Restful-API-CRUD-Operations-/84ec44450cfc1cd8672a80169797cc9310b9260c/restfulapicrud/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /restfulapicrud/router.py: -------------------------------------------------------------------------------- 1 | from employeeapi.viewsets import EmployeeViewset 2 | from rest_framework import routers 3 | 4 | router = routers.DefaultRouter() 5 | router.register('employee',EmployeeViewset) 6 | 7 | # localhost:p/api/employee/5 8 | # GET, POST, PUT, DELETE 9 | # list , retrive -------------------------------------------------------------------------------- /restfulapicrud/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for restfulapicrud project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.2.7. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.2/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/2.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'md1w9!&hu2*9p!7)e1)0&-7%n!kaabxcla97+38e@-t&f+(dik' 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 | 'employeeapi', 41 | 'rest_framework' 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'restfulapicrud.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'restfulapicrud.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.postgresql', 81 | 'NAME': 'restfulapiDB', 82 | 'USER':'postgres', 83 | 'PASSWORD':'postgres', 84 | 'HOST':'localhost' 85 | } 86 | } 87 | 88 | 89 | # Password validation 90 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/2.2/topics/i18n/ 110 | 111 | LANGUAGE_CODE = 'en-us' 112 | 113 | TIME_ZONE = 'UTC' 114 | 115 | USE_I18N = True 116 | 117 | USE_L10N = True 118 | 119 | USE_TZ = True 120 | 121 | 122 | # Static files (CSS, JavaScript, Images) 123 | # https://docs.djangoproject.com/en/2.2/howto/static-files/ 124 | 125 | STATIC_URL = '/static/' 126 | -------------------------------------------------------------------------------- /restfulapicrud/urls.py: -------------------------------------------------------------------------------- 1 | """restfulapicrud URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.2/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 | from .router import router 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('api/',include(router.urls)) 23 | ] 24 | -------------------------------------------------------------------------------- /restfulapicrud/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for restfulapicrud 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/2.2/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', 'restfulapicrud.settings') 15 | 16 | application = get_wsgi_application() 17 | --------------------------------------------------------------------------------