diff --git a/crud/__init__.py b/crud/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/crud/__pycache__/__init__.cpython-311.pyc b/crud/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..f4eaea0 Binary files /dev/null and b/crud/__pycache__/__init__.cpython-311.pyc differ diff --git a/crud/__pycache__/settings.cpython-311.pyc b/crud/__pycache__/settings.cpython-311.pyc new file mode 100644 index 0000000..1e2691e Binary files /dev/null and b/crud/__pycache__/settings.cpython-311.pyc differ diff --git a/crud/__pycache__/urls.cpython-311.pyc b/crud/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..f311f2a Binary files /dev/null and b/crud/__pycache__/urls.cpython-311.pyc differ diff --git a/crud/__pycache__/wsgi.cpython-311.pyc b/crud/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 0000000..670f055 Binary files /dev/null and b/crud/__pycache__/wsgi.cpython-311.pyc differ diff --git a/crud/asgi.py b/crud/asgi.py new file mode 100644 index 0000000..1dd4bdf --- /dev/null +++ b/crud/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for crud project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crud.settings') + +application = get_asgi_application() diff --git a/crud/settings.py b/crud/settings.py new file mode 100644 index 0000000..1e7fd97 --- /dev/null +++ b/crud/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for crud project. + +Generated by 'django-admin startproject' using Django 4.2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-3c&1v+t8r%j-!#3$252!fx6@-%%2&pq2ti5)sy#wuv1ws*-448' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'main', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'crud.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'crud.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/crud/urls.py b/crud/urls.py new file mode 100644 index 0000000..84340ad --- /dev/null +++ b/crud/urls.py @@ -0,0 +1,24 @@ +""" +URL configuration for crud project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path,include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('main.urls')), + +] diff --git a/crud/wsgi.py b/crud/wsgi.py new file mode 100644 index 0000000..27903b9 --- /dev/null +++ b/crud/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for crud project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crud.settings') + +application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..1978eb2 Binary files /dev/null and b/db.sqlite3 differ diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/__pycache__/__init__.cpython-311.pyc b/main/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..0fe574c Binary files /dev/null and b/main/__pycache__/__init__.cpython-311.pyc differ diff --git a/main/__pycache__/admin.cpython-311.pyc b/main/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..ec1f76a Binary files /dev/null and b/main/__pycache__/admin.cpython-311.pyc differ diff --git a/main/__pycache__/apps.cpython-311.pyc b/main/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..03fe2b4 Binary files /dev/null and b/main/__pycache__/apps.cpython-311.pyc differ diff --git a/main/__pycache__/forms.cpython-311.pyc b/main/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..8bce64a Binary files /dev/null and b/main/__pycache__/forms.cpython-311.pyc differ diff --git a/main/__pycache__/models.cpython-311.pyc b/main/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..e74d6b2 Binary files /dev/null and b/main/__pycache__/models.cpython-311.pyc differ diff --git a/main/__pycache__/urls.cpython-311.pyc b/main/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..f4e0dbf Binary files /dev/null and b/main/__pycache__/urls.cpython-311.pyc differ diff --git a/main/__pycache__/views.cpython-311.pyc b/main/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..0c872cf Binary files /dev/null and b/main/__pycache__/views.cpython-311.pyc differ diff --git a/main/admin.py b/main/admin.py new file mode 100644 index 0000000..a4af226 --- /dev/null +++ b/main/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin +from .models import AddUser + +# Register your models here. +@admin.register(AddUser) + +class AddUserAdmin(admin.ModelAdmin): + list_display=('id', 'name', 'email','age') \ No newline at end of file diff --git a/main/apps.py b/main/apps.py new file mode 100644 index 0000000..167f044 --- /dev/null +++ b/main/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MainConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'main' diff --git a/main/forms.py b/main/forms.py new file mode 100644 index 0000000..7ade798 --- /dev/null +++ b/main/forms.py @@ -0,0 +1,18 @@ +from django import forms +from django.core import validators +from .models import AddUser + +class AddForm(forms.ModelForm): + # name = forms.CharField(max_length=100) + # email = forms.EmailField(max_length=100) + # age = forms.IntegerField() + class Meta: + model = AddUser + fields = ['name','email','age'] + widgets ={ + 'name' : forms.TextInput(attrs={'class':'form-control'}), + 'email' : forms.EmailInput(attrs={'class':'form-control'}), + 'age' : forms.TextInput(attrs={'class':'form-control'}), + } + + \ No newline at end of file diff --git a/main/migrations/0001_initial.py b/main/migrations/0001_initial.py new file mode 100644 index 0000000..9171ebd --- /dev/null +++ b/main/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.2 on 2023-07-16 09:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='AddUser', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('email', models.EmailField(max_length=100)), + ('age', models.IntegerField()), + ], + ), + ] diff --git a/main/migrations/__init__.py b/main/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/migrations/__pycache__/0001_initial.cpython-311.pyc b/main/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..86e2382 Binary files /dev/null and b/main/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/main/migrations/__pycache__/__init__.cpython-311.pyc b/main/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..c1e006a Binary files /dev/null and b/main/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/main/models.py b/main/models.py new file mode 100644 index 0000000..a6ac3ea --- /dev/null +++ b/main/models.py @@ -0,0 +1,8 @@ +from django.db import models + +# Create your models here. + +class AddUser(models.Model): + name = models.CharField(max_length=100) + email = models.EmailField(max_length=100) + age = models.IntegerField() \ No newline at end of file diff --git a/main/templates/main/base.html b/main/templates/main/base.html new file mode 100644 index 0000000..6e946bc --- /dev/null +++ b/main/templates/main/base.html @@ -0,0 +1,22 @@ + + + + + + Document + + + +
+

Crud Project With Function Based View

+ + {% block content%} {% endblock content%} +
+ + + + + + + + \ No newline at end of file diff --git a/main/templates/main/show.html b/main/templates/main/show.html new file mode 100644 index 0000000..902bf15 --- /dev/null +++ b/main/templates/main/show.html @@ -0,0 +1,58 @@ +{% extends 'main/base.html' %} +{% load static %} +{% block content%} +
+
+
Add New Data
+
+ {% csrf_token %} + {{form.as_p}} + +
+ +
+ +
+ + + + + + + + + + + + + + + {% for l in li %} + + + + + + + + + + + + {% endfor %} + + +
IDNameEmailAgeActions
{{l.id}}{{l.name}}{{l.email}}{{l.age}} + Edit + +
+ {% csrf_token %} + +
+
+
+
+ + + +{% endblock content%} \ No newline at end of file diff --git a/main/templates/main/update.html b/main/templates/main/update.html new file mode 100644 index 0000000..02259d0 --- /dev/null +++ b/main/templates/main/update.html @@ -0,0 +1,20 @@ +{% extends 'main/base.html' %} + +{% block content%} +
+
+
Update Data
+
+ {% csrf_token %} + {{form.as_p}} + + Back To Home + +
+ + + +
+
+ +{% endblock content%} \ No newline at end of file diff --git a/main/tests.py b/main/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/main/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000..3e04c86 --- /dev/null +++ b/main/urls.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from django.urls import path,include +from . import views + +urlpatterns = [ + path('', views.home, name="home"), + path('delete//', views.delete_data, name="deletedata"), + path('update//', views.update_data, name="updatedata"), +] \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..8a7cfa5 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crud.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main()