├── Universidad ├── __init__.py ├── asgi.py ├── wsgi.py ├── urls.py └── settings.py ├── Aplicaciones └── Academico │ ├── __init__.py │ ├── migrations │ ├── __init__.py │ └── 0001_initial.py │ ├── tests.py │ ├── static │ ├── css │ │ └── gestionCursos.css │ └── js │ │ └── gestionCursos.js │ ├── apps.py │ ├── admin.py │ ├── urls.py │ ├── models.py │ ├── views.py │ └── templates │ ├── edicionCurso.html │ ├── base.html │ └── gestionCursos.html ├── .gitignore ├── preview1.JPG ├── preview2.JPG ├── Universidad.db ├── manage.py └── README.md /Universidad/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /env/ 2 | __pycache__/ 3 | *.py[cod] -------------------------------------------------------------------------------- /Aplicaciones/Academico/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /preview1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UskoKruM/django-crud-sqlite3/HEAD/preview1.JPG -------------------------------------------------------------------------------- /preview2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UskoKruM/django-crud-sqlite3/HEAD/preview2.JPG -------------------------------------------------------------------------------- /Universidad.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UskoKruM/django-crud-sqlite3/HEAD/Universidad.db -------------------------------------------------------------------------------- /Aplicaciones/Academico/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/static/css/gestionCursos.css: -------------------------------------------------------------------------------- 1 | th, 2 | td { 3 | text-align: center; 4 | vertical-align: middle; 5 | } 6 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AcademicoConfig(AppConfig): 5 | name = 'Academico' 6 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Curso 3 | 4 | # Register your models here. 5 | 6 | admin.site.register(Curso) -------------------------------------------------------------------------------- /Aplicaciones/Academico/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home), 6 | path('registrarCurso/', views.registrarCurso), 7 | path('edicionCurso/', views.edicionCurso), 8 | path('editarCurso/', views.editarCurso), 9 | path('eliminarCurso/', views.eliminarCurso) 10 | ] -------------------------------------------------------------------------------- /Aplicaciones/Academico/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | 6 | class Curso(models.Model): 7 | codigo = models.CharField(primary_key=True, max_length=6) 8 | nombre = models.CharField(max_length=50) 9 | creditos = models.PositiveSmallIntegerField() 10 | 11 | def __str__(self): 12 | texto = "{0} ({1})" 13 | return texto.format(self.nombre, self.creditos) 14 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/static/js/gestionCursos.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 3 | const btnEliminacion = document.querySelectorAll(".btnEliminacion"); 4 | 5 | btnEliminacion.forEach(btn => { 6 | btn.addEventListener('click', (e) => { 7 | const confirmacion = confirm('¿Seguro de eliminar el curso?'); 8 | if (!confirmacion) { 9 | e.preventDefault(); 10 | } 11 | }); 12 | }); 13 | 14 | })(); -------------------------------------------------------------------------------- /Universidad/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for Universidad 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.1/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', 'Universidad.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Universidad/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for Universidad 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.1/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', 'Universidad.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.3 on 2020-11-13 03:36 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='Curso', 16 | fields=[ 17 | ('codigo', models.CharField(max_length=6, primary_key=True, serialize=False)), 18 | ('nombre', models.CharField(max_length=50)), 19 | ('creditos', models.PositiveSmallIntegerField()), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /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', 'Universidad.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 | -------------------------------------------------------------------------------- /Universidad/urls.py: -------------------------------------------------------------------------------- 1 | """Universidad URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/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('', include('Aplicaciones.Academico.urls')) 22 | ] 23 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from .models import Curso 3 | from django.contrib import messages 4 | 5 | # Create your views here. 6 | 7 | 8 | def home(request): 9 | cursosListados = Curso.objects.all() 10 | messages.success(request, '¡Cursos listados!') 11 | return render(request, "gestionCursos.html", {"cursos": cursosListados}) 12 | 13 | 14 | def registrarCurso(request): 15 | codigo = request.POST['txtCodigo'] 16 | nombre = request.POST['txtNombre'] 17 | creditos = request.POST['numCreditos'] 18 | 19 | curso = Curso.objects.create( 20 | codigo=codigo, nombre=nombre, creditos=creditos) 21 | messages.success(request, '¡Curso registrado!') 22 | return redirect('/') 23 | 24 | 25 | def edicionCurso(request, codigo): 26 | curso = Curso.objects.get(codigo=codigo) 27 | return render(request, "edicionCurso.html", {"curso": curso}) 28 | 29 | 30 | def editarCurso(request): 31 | codigo = request.POST['txtCodigo'] 32 | nombre = request.POST['txtNombre'] 33 | creditos = request.POST['numCreditos'] 34 | 35 | curso = Curso.objects.get(codigo=codigo) 36 | curso.nombre = nombre 37 | curso.creditos = creditos 38 | curso.save() 39 | 40 | messages.success(request, '¡Curso actualizado!') 41 | 42 | return redirect('/') 43 | 44 | 45 | def eliminarCurso(request, codigo): 46 | curso = Curso.objects.get(codigo=codigo) 47 | curso.delete() 48 | 49 | messages.success(request, '¡Curso eliminado!') 50 | 51 | return redirect('/') 52 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/templates/edicionCurso.html: -------------------------------------------------------------------------------- 1 | {% extends "./base.html" %} 2 | 3 | {% block title %} Gestión de Cursos {% endblock %} 4 | 5 | {% block body %} 6 |
7 |
8 |

Edición de Curso

9 |
10 |
11 |
{% csrf_token %} 12 |
13 | 15 |
16 |
17 | 19 |
20 |
21 | 23 |
24 |
25 | 26 |
27 |
28 |
29 |
30 |
31 |
32 | {% endblock %} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django-CRUD-SQLite3 2 | 3 | CRUD completo con Python, Django y una base de datos SQLite3, usando el patrón de arquitectura MTV (Modelo - Plantilla - Vista), el ORM de Django, el framework CSS Bootstrap y control de eventos con JavaScript. 4 | 5 |
6 | 7 | ![](./preview1.JPG) 8 |

9 | ![](./preview2.JPG) 10 | 11 | # 🌍 Por si deseas contactarme 👨‍💻 : 12 | 13 | [![LinkedIn](https://img.shields.io/badge/LinkedIn-Oscar_Garcia-0077B5?style=for-the-badge&logo=linkedin&logoColor=white&labelColor=101010)](https://pe.linkedin.com/in/uskokrum2010) 14 | [![YouTube](https://img.shields.io/badge/YouTube-UskoKruM2010-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=101010)](https://youtube.com/uskokrum2010) 15 | [![Twitter](https://img.shields.io/badge/Twitter-@uskokrum2010-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white&labelColor=101010)](https://twitter.com/uskokrum2010) 16 | [![Instagram](https://img.shields.io/badge/Instagram-@uskokrum2010-E4405F?style=for-the-badge&logo=instagram&logoColor=white&labelColor=101010)](https://instagram.com/uskokrum2010) 17 | [![Facebook](https://img.shields.io/badge/Facebook-@uskokrum2010-1877F2?style=for-the-badge&logo=facebook&logoColor=white&labelColor=101010)](https://facebook.com/uskokrum2010) 18 | [![Udemy](https://img.shields.io/badge/Udemy-Oscar_Garcia-EC5252?style=for-the-badge&logo=udemy&logoColor=white&labelColor=101010)](https://www.udemy.com/course/sql-para-administracion-de-bases-de-datos-con-mysql/) 19 | [![Web](https://img.shields.io/badge/My_Website-uskokrum2010.com-14a1f0?style=for-the-badge&logo=dev.to&logoColor=white&labelColor=101010)](https://uskokrum2010.com) 20 | [![Email](https://img.shields.io/badge/uskokrum2010@gmail.com-mi_email_personal-D14836?style=for-the-badge&logo=gmail&logoColor=white&labelColor=101010)](mailto:uskokrum2010@gmail.com) 21 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% load static %} 6 | 7 | 8 | {% block title %} {% endblock %} 9 | 11 | 12 | 13 | 14 | 15 | 32 |
33 | {% block body %} 34 | 35 | {% endblock %} 36 |
37 | 40 | 43 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Aplicaciones/Academico/templates/gestionCursos.html: -------------------------------------------------------------------------------- 1 | {% extends "./base.html" %} 2 | 3 | {% block title %} Gestión de Cursos {% endblock %} 4 | 5 | {% block body %} 6 |
7 |
8 | {% if messages %} 9 | {% for message in messages %} 10 |
11 | 12 | {{ message }} 13 |
14 | {% endfor %} 15 | {% endif %} 16 |

Gestión de Curso

17 |
18 |
19 |
{% csrf_token %} 20 |
21 | 23 |
24 |
25 | 27 |
28 |
29 | 31 |
32 |
33 | 34 |
35 |
36 |
37 |
38 |
39 |
40 |

Listado de Cursos

41 |
42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | {% for c in cursos %} 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {% endfor %} 63 | 64 |
#CódigoNombreCréditosOpciones
{{forloop.counter}}{{c.codigo}}{{c.nombre}}{{c.creditos}}EditarEliminar
65 |
66 |
67 |
68 | {% endblock %} -------------------------------------------------------------------------------- /Universidad/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for Universidad project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/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/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'vk#(u6aky**#-o4rv93bx_)k^2^h003s%qr%a!9@pzw@p*)-lo' 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 | 'Aplicaciones.Academico' 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'Universidad.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'Universidad.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': 'Universidad.db', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'es-pe' 108 | 109 | TIME_ZONE = 'America/Lima' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | --------------------------------------------------------------------------------