├── README.md
└── employee_project
├── appStructure.txt
├── db.sqlite3
├── employee_project
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-37.pyc
│ ├── settings.cpython-37.pyc
│ ├── urls.cpython-37.pyc
│ └── wsgi.cpython-37.pyc
├── settings.py
├── urls.py
└── wsgi.py
├── employee_register
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-37.pyc
│ ├── admin.cpython-37.pyc
│ ├── forms.cpython-37.pyc
│ ├── models.cpython-37.pyc
│ ├── urls.cpython-37.pyc
│ └── views.cpython-37.pyc
├── admin.py
├── apps.py
├── forms.py
├── migrations
│ ├── 0001_initial.py
│ ├── __init__.py
│ └── __pycache__
│ │ ├── 0001_initial.cpython-37.pyc
│ │ └── __init__.cpython-37.pyc
├── models.py
├── templates
│ └── employee_register
│ │ ├── base.html
│ │ ├── employee_form.html
│ │ └── employee_list.html
├── tests.py
├── urls.py
└── views.py
└── manage.py
/README.md:
--------------------------------------------------------------------------------
1 | # Django-CRUD-Operations
2 | Complete Django CRUD Operations with PostgreSQL
3 |
4 | Content Discussed :
5 | - Django CRUD Operation
6 | - Design Django Form with Bootstrap and crispy forms
7 | - Display DropDown in Django Form
8 |
9 | ## Get the Code
10 |
11 | ```
12 | $ git clone https://github.com/CodAffection/Django-CRUD-Operations.git
13 | ```
14 |
15 | ## How it works ?
16 |
17 | :tv: Video tutorial on this same topic
18 | Url : https://youtu.be/N6jzspc2kds
19 |
20 |
23 |
24 |
25 | | :bar_chart: | List of Tutorials | | :moneybag: | Support Us |
26 | |--------------------------:|:---------------------|---|---------------------:|:-------------------------------------|
27 | | Angular |http://bit.ly/2KQN9xF | |Paypal | https://goo.gl/bPcyXW |
28 | | Asp.Net Core |http://bit.ly/30fPDMg | |Amazon Affiliate | https://geni.us/JDzpE |
29 | | React |http://bit.ly/325temF | |
30 | | Python |http://bit.ly/2ws4utg | | :point_right: | Follow Us |
31 | | Node.js |https://goo.gl/viJcFs | |Website |http://www.codaffection.com |
32 | | Asp.Net MVC |https://goo.gl/gvjUJ7 | |YouTube |https://www.youtube.com/codaffection |
33 | | Flutter |https://bit.ly/3ggmmJz| |Facebook |https://www.facebook.com/codaffection |
34 | | Web API |https://goo.gl/itVayJ | |Twitter |https://twitter.com/CodAffection |
35 | | MEAN Stack |https://goo.gl/YJPPAH | |
36 | | C# Tutorial |https://goo.gl/s1zJxo | |
37 | | Asp.Net WebForm |https://goo.gl/GXC2aJ | |
38 | | C# WinForm |https://goo.gl/vHS9Hd | |
39 | | MS SQL |https://goo.gl/MLYS9e | |
40 | | Crystal Report |https://goo.gl/5Vou7t | |
41 | | CG Exercises in C Program |https://goo.gl/qEWJCs | |
42 |
--------------------------------------------------------------------------------
/employee_project/appStructure.txt:
--------------------------------------------------------------------------------
1 | ● employee_project
2 | |
3 | +---● employee_register (app folder)
4 | | |
5 | | +--● migrations (includes files related to migrations)
6 | | |
7 | | +--● templates
8 | | | |--● employee_register
9 | | | | |--base.html
10 | | | | |--employee_form.html
11 | | | | |--employee_list.html
12 | | |
13 | | |-- models.py
14 | | |-- forms.py
15 | | |-- urls.py
16 | | |-- views.py
17 | |
18 | +---● employee_project (project folder)
19 | | |
20 | | |--settings.py
21 | | |--urls.py
--------------------------------------------------------------------------------
/employee_project/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/db.sqlite3
--------------------------------------------------------------------------------
/employee_project/employee_project/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_project/__init__.py
--------------------------------------------------------------------------------
/employee_project/employee_project/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_project/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_project/__pycache__/settings.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_project/__pycache__/settings.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_project/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_project/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_project/__pycache__/wsgi.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_project/__pycache__/wsgi.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_project/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for employee_project project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.2.5.
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 = 'foq211^89zn=-bym^kxc@ue5ji3xr!17lvi34diz8q$k&g)ey$'
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 | 'employee_register',
41 | 'crispy_forms'
42 | ]
43 |
44 | CRISPY_TEMPLATE_PACK = 'bootstrap4'
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 = 'employee_project.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 = 'employee_project.wsgi.application'
75 |
76 |
77 | # Database
78 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
79 |
80 | DATABASES = {
81 | 'default': {
82 | 'ENGINE': 'django.db.backends.postgresql',
83 | 'NAME': 'EmployeeDB',
84 | 'USER': 'postgres',
85 | 'PASSWORD': 'postgres',
86 | 'HOST': 'localhost'
87 | }
88 | }
89 |
90 |
91 | # Password validation
92 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
93 |
94 | AUTH_PASSWORD_VALIDATORS = [
95 | {
96 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
97 | },
98 | {
99 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
100 | },
101 | {
102 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
103 | },
104 | {
105 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
106 | },
107 | ]
108 |
109 |
110 | # Internationalization
111 | # https://docs.djangoproject.com/en/2.2/topics/i18n/
112 |
113 | LANGUAGE_CODE = 'en-us'
114 |
115 | TIME_ZONE = 'UTC'
116 |
117 | USE_I18N = True
118 |
119 | USE_L10N = True
120 |
121 | USE_TZ = True
122 |
123 |
124 | # Static files (CSS, JavaScript, Images)
125 | # https://docs.djangoproject.com/en/2.2/howto/static-files/
126 |
127 | STATIC_URL = '/static/'
128 |
--------------------------------------------------------------------------------
/employee_project/employee_project/urls.py:
--------------------------------------------------------------------------------
1 | """employee_project 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 |
19 | urlpatterns = [
20 | path('admin/', admin.site.urls),
21 | path('employee/',include('employee_register.urls'))
22 | ]
23 |
--------------------------------------------------------------------------------
/employee_project/employee_project/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for employee_project 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', 'employee_project.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/employee_project/employee_register/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__init__.py
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/admin.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/admin.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/forms.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/forms.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/models.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/models.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/urls.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/urls.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/__pycache__/views.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/__pycache__/views.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/employee_project/employee_register/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class EmployeeRegisterConfig(AppConfig):
5 | name = 'employee_register'
6 |
--------------------------------------------------------------------------------
/employee_project/employee_register/forms.py:
--------------------------------------------------------------------------------
1 | from django import forms
2 | from .models import Employee
3 |
4 |
5 | class EmployeeForm(forms.ModelForm):
6 |
7 | class Meta:
8 | model = Employee
9 | fields = ('fullname','mobile','emp_code','position')
10 | labels = {
11 | 'fullname':'Full Name',
12 | 'emp_code':'EMP. Code'
13 | }
14 |
15 | def __init__(self, *args, **kwargs):
16 | super(EmployeeForm,self).__init__(*args, **kwargs)
17 | self.fields['position'].empty_label = "Select"
18 | self.fields['emp_code'].required = False
19 |
--------------------------------------------------------------------------------
/employee_project/employee_register/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.2.5 on 2019-10-28 08:08
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | initial = True
10 |
11 | dependencies = [
12 | ]
13 |
14 | operations = [
15 | migrations.CreateModel(
16 | name='Position',
17 | fields=[
18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19 | ('title', models.CharField(max_length=50)),
20 | ],
21 | ),
22 | migrations.CreateModel(
23 | name='Employee',
24 | fields=[
25 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26 | ('fullname', models.CharField(max_length=100)),
27 | ('emp_code', models.CharField(max_length=3)),
28 | ('mobile', models.CharField(max_length=15)),
29 | ('position', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='employee_register.Position')),
30 | ],
31 | ),
32 | ]
33 |
--------------------------------------------------------------------------------
/employee_project/employee_register/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/migrations/__init__.py
--------------------------------------------------------------------------------
/employee_project/employee_register/migrations/__pycache__/0001_initial.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/migrations/__pycache__/0001_initial.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/migrations/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodAffection/Django-CRUD-Operations/46bc6ed72f0bcdbf9388ccb0ea5fae573ef7eb7c/employee_project/employee_register/migrations/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/employee_project/employee_register/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
5 | class Position(models.Model):
6 | title = models.CharField(max_length=50)
7 |
8 | def __str__(self):
9 | return self.title
10 |
11 | class Employee(models.Model):
12 | fullname = models.CharField(max_length=100)
13 | emp_code = models.CharField(max_length=3)
14 | mobile= models.CharField(max_length=15)
15 | position= models.ForeignKey(Position,on_delete=models.CASCADE)
16 |
17 |
--------------------------------------------------------------------------------
/employee_project/employee_register/templates/employee_register/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Python Django project for implementing CRUD operations
20 |Full Name | 9 |Mobile | 10 |Position | 11 |12 | 13 | Add New 14 | 15 | | 16 |
{{employee.fullname}} | 22 |{{employee.mobile}} | 23 |{{employee.position}} | 24 |25 | 26 | 27 | 28 | 34 | | 35 |