├── .gitignore ├── README.md └── crudproject ├── crudapp ├── __init__.py ├── admin.py ├── apps.py ├── forms.py ├── models.py ├── tests.py ├── urls.py └── views.py ├── crudproject ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── db.sqlite3 ├── manage.py ├── requirements.txt └── templates ├── crudapp ├── confirmation.html ├── order.html └── show.html └── layout.html /.gitignore: -------------------------------------------------------------------------------- 1 | /crudproject/.env 2 | /crudproject/crudproject/__pycache__ 3 | /crudproject/crudapp/__pycache__ 4 | /crudproject/crudapp/migrations -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building a Django CRUD (Create, Retrieve, Update and Delete) Project Using Function-Based Views 2 | 3 | Django is a powerful Python web framework that simplifies web development by providing a clean and pragmatic design. One of the most common tasks in web development is creating CRUD (Create, Read, Update, Delete) functionality for your application. In this article, we'll explore how to create a Django CRUD project using function-based views. 4 | 5 | ### Prerequisites 6 | 7 | Before we dive into building our CRUD project, make sure you have the following prerequisites in place: 8 | 9 | 1. Python and Django: Ensure you have Python installed on your system. You can install Django using pip: 10 | ```python 11 | pip install django 12 | ``` 13 | 14 | 2. Database: Decide on the database you want to use. By default, Django uses SQLite, but you can configure it to use other databases like PostgreSQL, MySQL, or Oracle. 15 | 16 | 3. Text Editor or IDE: Choose a code editor or integrated development environment (IDE) of your preference. Popular choices include Visual Studio Code, PyCharm, or Sublime Text. 17 | 18 | ### Setting Up Your Django Project 19 | 20 | Let's start by creating a new Django project and a new app within that project. Open your terminal and run the following commands: 21 | 22 | ```python 23 | django-admin startproject crudproject 24 | cd crudproject 25 | python manage.py startapp crudapp 26 | ``` 27 | 28 | We've created a new project named "crudproject" and an app named "crudapp." 29 | 30 | ### Application Registration: you need to configure in your settings.py file 31 | 32 | Make sure your app (myapp) is included in the INSTALLED_APPS list: 33 | 34 | ```python 35 | INSTALLED_APPS = [ 36 | # ... 37 | 'myapp', 38 | ] 39 | ``` 40 | 41 | ### Defining Models 42 | 43 | In Django, models are Python classes that define the structure of your database tables. For our CRUD project, let's assume we want to manage a list of orders. Create a model for the orders in `crudapp/models.py`: 44 | 45 | ```python 46 | from django.db import models 47 | 48 | # Create your models here. 49 | class Orders(models.Model): 50 | oid = models.IntegerField(primary_key=True) 51 | fname = models.CharField(max_length=20) 52 | lname = models.CharField(max_length=20) 53 | price = models.FloatField() 54 | mail = models.EmailField() 55 | addr = models.CharField(max_length=50) 56 | ``` 57 | 58 | Now, it's time to create the database tables for our models. Run the following commands to create the migrations and apply them: 59 | 60 | ```python 61 | python manage.py makemigrations 62 | python manage.py migrate 63 | ``` 64 | 65 | ### Creating Forms 66 | 67 | We mentioned using a form for creating and updating orders. You can define the form in `crudapp/forms.py`: 68 | 69 | ```python 70 | from django import forms 71 | from .models import Orders 72 | 73 | class OrderForm(forms.ModelForm): 74 | class Meta: 75 | model = Orders 76 | fields = '__all__' 77 | 78 | labels = { 79 | 'oid': 'Order ID', 80 | 'fname' : 'First Name', 81 | 'lname' : 'Last Name.' , 82 | 'price' : 'Price' , 83 | 'mail' : 'Email ID', 84 | 'addr' : 'Address' , 85 | } 86 | 87 | widgets ={ 88 | 'oid' : forms.NumberInput(attrs={'placeholder': 'eg. 101'}), 89 | 'fname' : forms.TextInput(attrs={'placeholder': 'eg. Prosenjeet'}), 90 | 'lname' : forms.TextInput(attrs={'placeholder': 'eg. Shil'}), 91 | 'price' : forms.NumberInput(attrs={'placeholder': 'eg. 10000'}), 92 | 'mail' : forms.EmailInput(attrs={'placeholder': 'eg. abc@xyz.com'}), 93 | 'addr' : forms.Textarea(attrs={'placeholder': 'eg. IN'}), 94 | } 95 | ``` 96 | 97 | ### Creating Function-Based Views 98 | 99 | Function-based views are a simple and straightforward way to handle CRUD operations in Django. In this example, we'll create views for creating, reading, updating, and deleting orders. 100 | 101 | 1. Create a Order (Create View) 102 | In `crudapp/views.py`, define a view function for creating a new order: 103 | 104 | ```python 105 | from django.shortcuts import redirect, render 106 | from .forms import OrderForm 107 | from .models import Orders 108 | 109 | # Create your views here. 110 | def orderFormView(request): 111 | form = OrderForm() 112 | if request.method == 'POST': 113 | form = OrderForm(request.POST) 114 | if form.is_valid(): 115 | form.save() 116 | return redirect('show_url') 117 | template_name = 'crudapp/order.html' 118 | context = {'form': form} 119 | return render(request, template_name, context) 120 | ``` 121 | 122 | In this view, we handle both GET and POST requests. If it's a GET request, we render a form for creating a new order. If it's a POST request, we validate the form data and save the new order if it's valid. 123 | 124 | 2. Read Orders (List View) 125 | Now, let's create a view to display a list of all books in `crudapp/views.py`: 126 | 127 | ```python 128 | def showView(request): 129 | obj = Orders.objects.all() 130 | template_name = 'crudapp/show.html' 131 | context = {'obj': obj} 132 | return render(request, template_name, context) 133 | ``` 134 | 135 | This view retrieves all orders from the database and renders them using a template. 136 | 137 | 3. Update a Order (Update View) 138 | To update a order, create a view in `crudapp/views.py`: 139 | 140 | ```python 141 | def updateView(request, f_oid): 142 | obj = Orders.objects.get(oid=f_oid) 143 | form = OrderForm(instance=obj) 144 | if request.method == 'POST': 145 | form = OrderForm(request.POST, instance=obj) 146 | if form.is_valid(): 147 | form.save() 148 | return redirect('show_url') 149 | template_name = 'crudapp/order.html' 150 | context = {'form': form} 151 | return render(request, template_name, context) 152 | ``` 153 | 154 | 4. Delete a Order (Delete View) 155 | Finally, let's create a view to delete a order in `crudapp/views.py`: 156 | 157 | ```python 158 | def deleteView(request, f_oid): 159 | obj = Orders.objects.get(oid=f_oid) 160 | if request.method == 'POST': 161 | obj.delete() 162 | return redirect('show_url') 163 | template_name = 'crudapp/confirmation.html' 164 | context = {'obj': obj} 165 | return render(request, template_name, context) 166 | ``` 167 | 168 | In this view, we confirm the order deletion with a confirmation page. 169 | 170 | ### Creating Templates 171 | 172 | Add Bootstrap and Crispy forms for styling 173 | Before creating templates, let’s add Bootstrap and Crispy Forms for styling our application. 174 | 175 | ``` 176 | pip install crispy-bootstrap5 177 | pip install django-crispy-forms 178 | ``` 179 | ### Add Bootstrap Crispy forms for styling form and navbar 180 | 181 | ```python 182 | INSTALLED_APPS = [ 183 | # ... 184 | 'crispy_forms', 185 | 'crispy_bootstrap5', 186 | ] 187 | 188 | CRISPY_TEMPLATE_PACK = 'bootstrap5' 189 | ``` 190 | 191 | Now, create HTML templates for the views in the crudproject/templates directory. You'll need templates for the following views: 192 | 193 | layout.html: for creating base html file with navbar. 194 | 195 | Similarly, create HTML templates for the views in the crudproject/templates/crudapp directory. You'll need templates for the following views: 196 | 197 | order.html: For the create and update forms. 198 | show.html: For listing all orders. 199 | confirmation.html: For confirming order deletion. 200 | 201 | Below, are the templates for base file and the three views we discussed earlier: 202 | 203 | `crudproject/templates/layout.html` 204 | 205 | ```html 206 | 207 | 208 | 209 | 210 | 211 | {% block title %} 212 | Layout Page 213 | {% endblock %} 214 | 215 | 216 | 217 | 218 | 235 | 236 | {% block content %} 237 | {% endblock %} 238 | 239 | 240 | 241 | 242 | 243 | 244 | ``` 245 | 246 | `crudproject/templates/crudapp/orders.html` 247 | 248 | ```html 249 | {% extends 'layout.html' %} 250 | {% load crispy_forms_tags %} 251 | 252 | {% block title %} 253 | Add Page 254 | {% endblock %} 255 | 256 | {% block content %} 257 |

Order Form

258 |
259 |
260 | {% csrf_token %} 261 | {{form|crispy}} 262 | 263 |
264 |
265 | {% endblock %} 266 | ``` 267 | 268 | `crudproject/templates/crudapp/show.html` 269 | 270 | ```html 271 | {% extends 'layout.html' %} 272 | 273 | {% block title %} 274 | Show Page 275 | {% endblock %} 276 | 277 | {% block content %} 278 |

Show Orders

279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | {% for i in obj %} 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 304 | 305 | {% endfor %} 306 | 307 |
Order IDFirst NameLast NamePriceEmail IDAddressActions
{{i.oid}}{{i.fname}}{{i.lname}}{{i.price}}{{i.mail}}{{i.addr}} 301 |    302 | 303 |
308 | {% endblock %} 309 | 310 | ``` 311 | 312 | `crudproject/templates/crudapp/confirmation.html` 313 | 314 | ```html 315 | {% extends 'layout.html' %} 316 | 317 | {% block title %} 318 | Confirmation Page 319 | {% endblock %} 320 | 321 | {% block content %} 322 |
323 |
324 | {% csrf_token %} 325 |

Are you sure you want to delete this data?

326 | 327 | 328 |
329 |
330 | {% endblock %} 331 | ``` 332 | 333 | ### Wiring Up URLs 334 | 335 | Finally, configure the URLs for your views. In your project's crudproject/urls.py file, include the URLs for the crudapp app: 336 | 337 | 338 | ```python 339 | from django.contrib import admin 340 | from django.urls import path, include 341 | 342 | urlpatterns = [ 343 | path('admin/', admin.site.urls), 344 | path('', include('crudapp.urls')) 345 | ] 346 | ``` 347 | 348 | Then, in your app's crudpp/urls.py file, define the URLs for your views: 349 | 350 | ```python 351 | from django.urls import path 352 | from . import views 353 | 354 | urlpatterns = [ 355 | path('ofv/', views.orderFormView, name='order_url'), 356 | path('sv/', views.showView, name='show_url'), 357 | path('up/', views.updateView, name= 'update_url'), 358 | path('del/', views.deleteView, name= 'delete_url'), 359 | ] 360 | ``` 361 | 362 | ### Testing Your CRUD Project 363 | 364 | With everything set up, you can start your Django development server: 365 | 366 | ```python 367 | python manage.py runserver 368 | ``` 369 | 370 | Visit http://localhost:8000/ in your browser, and you should be able to create, read, update, and delete orders in your Django CRUD project using function-based views. 371 | 372 | In this tutorial, you've learned how to create a Django CRUD project using function-based views. You can further enhance your project by adding features like authentication, pagination, or search functionality. Django's flexibility and extensive ecosystem make it a great choice 373 | 374 | -------------------------------------------------------------------------------- /crudproject/crudapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prosenjeetshil/django-crud-operations-tutorial/69e276ee77c74d590d602bb7e70cb01cd219dd96/crudproject/crudapp/__init__.py -------------------------------------------------------------------------------- /crudproject/crudapp/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /crudproject/crudapp/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CrudappConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'crudapp' 7 | -------------------------------------------------------------------------------- /crudproject/crudapp/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from .models import Orders 3 | 4 | class OrderForm(forms.ModelForm): 5 | class Meta: 6 | model = Orders 7 | fields = '__all__' 8 | 9 | labels = { 10 | 'oid': 'Order ID', 11 | 'fname' : 'First Name', 12 | 'lname' : 'Last Name.' , 13 | 'price' : 'Price' , 14 | 'mail' : 'Email ID', 15 | 'addr' : 'Address' , 16 | } 17 | 18 | widgets ={ 19 | 'oid' : forms.NumberInput(attrs={'placeholder': 'eg. 101'}), 20 | 'fname' : forms.TextInput(attrs={'placeholder': 'eg. Prosenjeet'}), 21 | 'lname' : forms.TextInput(attrs={'placeholder': 'eg. Shil'}), 22 | 'price' : forms.NumberInput(attrs={'placeholder': 'eg. 10000'}), 23 | 'mail' : forms.EmailInput(attrs={'placeholder': 'eg. abc@xyz.com'}), 24 | 'addr' : forms.Textarea(attrs={'placeholder': 'eg. IN'}), 25 | } -------------------------------------------------------------------------------- /crudproject/crudapp/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | class Orders(models.Model): 5 | oid = models.IntegerField(primary_key=True) 6 | fname = models.CharField(max_length=20) 7 | lname = models.CharField(max_length=20) 8 | price = models.FloatField() 9 | mail = models.EmailField() 10 | addr = models.CharField(max_length=50) 11 | 12 | def __str__(self): 13 | return f'{self.fname}' -------------------------------------------------------------------------------- /crudproject/crudapp/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /crudproject/crudapp/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('ofv/', views.orderFormView, name='order_url'), 6 | path('sv/', views.showView, name='show_url'), 7 | path('up/', views.updateView, name= 'update_url'), 8 | path('del/', views.deleteView, name= 'delete_url'), 9 | ] -------------------------------------------------------------------------------- /crudproject/crudapp/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import redirect, render 2 | from .forms import OrderForm 3 | from .models import Orders 4 | 5 | # Create your views here. 6 | def orderFormView(request): 7 | form = OrderForm() 8 | if request.method == 'POST': 9 | form = OrderForm(request.POST) 10 | if form.is_valid(): 11 | form.save() 12 | return redirect('show_url') 13 | template_name = 'crudapp/order.html' 14 | context = {'form': form} 15 | return render(request, template_name, context) 16 | 17 | def showView(request): 18 | obj = Orders.objects.all() 19 | template_name = 'crudapp/show.html' 20 | context = {'obj': obj} 21 | return render(request, template_name, context) 22 | 23 | def updateView(request, f_oid): 24 | obj = Orders.objects.get(oid=f_oid) 25 | form = OrderForm(instance=obj) 26 | if request.method == 'POST': 27 | form = OrderForm(request.POST, instance=obj) 28 | if form.is_valid(): 29 | form.save() 30 | return redirect('show_url') 31 | template_name = 'crudapp/order.html' 32 | context = {'form': form} 33 | return render(request, template_name, context) 34 | 35 | def deleteView(request, f_oid): 36 | obj = Orders.objects.get(oid=f_oid) 37 | if request.method == 'POST': 38 | obj.delete() 39 | return redirect('show_url') 40 | template_name = 'crudapp/confirmation.html' 41 | context = {'obj': obj} 42 | return render(request, template_name, context) 43 | -------------------------------------------------------------------------------- /crudproject/crudproject/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prosenjeetshil/django-crud-operations-tutorial/69e276ee77c74d590d602bb7e70cb01cd219dd96/crudproject/crudproject/__init__.py -------------------------------------------------------------------------------- /crudproject/crudproject/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crudproject 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.2/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', 'crudproject.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crudproject/crudproject/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for crudproject project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.2.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.2/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.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | from decouple import config 24 | 25 | SECRET_KEY = config("SECRET_KEY") 26 | 27 | # SECURITY WARNING: don't run with debug turned on in production! 28 | DEBUG = True 29 | 30 | ALLOWED_HOSTS = [] 31 | 32 | 33 | # Application definition 34 | 35 | INSTALLED_APPS = [ 36 | 'django.contrib.admin', 37 | 'django.contrib.auth', 38 | 'django.contrib.contenttypes', 39 | 'django.contrib.sessions', 40 | 'django.contrib.messages', 41 | 'django.contrib.staticfiles', 42 | 'crudapp', 43 | 'crispy_forms', 44 | 'crispy_bootstrap5', 45 | ] 46 | 47 | CRISPY_TEMPLATE_PACK = 'bootstrap5' 48 | 49 | MIDDLEWARE = [ 50 | 'django.middleware.security.SecurityMiddleware', 51 | 'django.contrib.sessions.middleware.SessionMiddleware', 52 | 'django.middleware.common.CommonMiddleware', 53 | 'django.middleware.csrf.CsrfViewMiddleware', 54 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 55 | 'django.contrib.messages.middleware.MessageMiddleware', 56 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 57 | ] 58 | 59 | ROOT_URLCONF = 'crudproject.urls' 60 | 61 | TEMPLATES = [ 62 | { 63 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 64 | 'DIRS': ['templates'], 65 | 'APP_DIRS': True, 66 | 'OPTIONS': { 67 | 'context_processors': [ 68 | 'django.template.context_processors.debug', 69 | 'django.template.context_processors.request', 70 | 'django.contrib.auth.context_processors.auth', 71 | 'django.contrib.messages.context_processors.messages', 72 | ], 73 | }, 74 | }, 75 | ] 76 | 77 | WSGI_APPLICATION = 'crudproject.wsgi.application' 78 | 79 | 80 | # Database 81 | # https://docs.djangoproject.com/en/4.2/ref/settings/#databases 82 | 83 | DATABASES = { 84 | 'default': { 85 | 'ENGINE': 'django.db.backends.sqlite3', 86 | 'NAME': BASE_DIR / 'db.sqlite3', 87 | } 88 | } 89 | 90 | 91 | # Password validation 92 | # https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/ 112 | 113 | LANGUAGE_CODE = 'en-us' 114 | 115 | TIME_ZONE = 'UTC' 116 | 117 | USE_I18N = True 118 | 119 | USE_TZ = True 120 | 121 | 122 | # Static files (CSS, JavaScript, Images) 123 | # https://docs.djangoproject.com/en/4.2/howto/static-files/ 124 | 125 | STATIC_URL = 'static/' 126 | 127 | # Default primary key field type 128 | # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field 129 | 130 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 131 | -------------------------------------------------------------------------------- /crudproject/crudproject/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for crudproject project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import path, include 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('', include('crudapp.urls')) 23 | ] 24 | -------------------------------------------------------------------------------- /crudproject/crudproject/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crudproject 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.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', 'crudproject.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /crudproject/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prosenjeetshil/django-crud-operations-tutorial/69e276ee77c74d590d602bb7e70cb01cd219dd96/crudproject/db.sqlite3 -------------------------------------------------------------------------------- /crudproject/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', 'crudproject.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 | -------------------------------------------------------------------------------- /crudproject/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.7.2 2 | Django==4.2.5 3 | python-decouple==3.8 4 | sqlparse==0.4.4 5 | typing_extensions==4.7.1 6 | tzdata==2023.3 7 | -------------------------------------------------------------------------------- /crudproject/templates/crudapp/confirmation.html: -------------------------------------------------------------------------------- 1 | {% extends 'layout.html' %} 2 | 3 | {% block title %} 4 | Confirmation Page 5 | {% endblock %} 6 | 7 | {% block content %} 8 |
9 |
10 | {% csrf_token %} 11 |

Are you sure you want to delete this data?

12 | 13 | 14 |
15 |
16 | {% endblock %} -------------------------------------------------------------------------------- /crudproject/templates/crudapp/order.html: -------------------------------------------------------------------------------- 1 | {% extends 'layout.html' %} 2 | {% load crispy_forms_tags %} 3 | 4 | {% block title %} 5 | Add Page 6 | {% endblock %} 7 | 8 | {% block content %} 9 |

Order Form

10 |
11 |
12 | {% csrf_token %} 13 | {{form|crispy}} 14 | 15 |
16 |
17 | {% endblock %} -------------------------------------------------------------------------------- /crudproject/templates/crudapp/show.html: -------------------------------------------------------------------------------- 1 | {% extends 'layout.html' %} 2 | 3 | {% block title %} 4 | Show Page 5 | {% endblock %} 6 | 7 | {% block content %} 8 |

Show Orders

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {% for i in obj %} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | {% endfor %} 36 | 37 |
Order IDFirst NameLast NamePriceEmail IDAddressActions
{{i.oid}}{{i.fname}}{{i.lname}}{{i.price}}{{i.mail}}{{i.addr}} 31 |    32 | 33 |
38 | {% endblock %} -------------------------------------------------------------------------------- /crudproject/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {% block title %} 7 | Layout Page 8 | {% endblock %} 9 | 10 | 11 | 12 | 13 | 30 | 31 | {% block content %} 32 | {% endblock %} 33 | 34 | 35 | 36 | 37 | 38 | --------------------------------------------------------------------------------