From 5d3a07ae0e9bbdfce24e6254a6fd1632ab9ad2d9 Mon Sep 17 00:00:00 2001 From: "jp.av.dev" Date: Fri, 2 Jul 2021 22:10:23 -0400 Subject: [PATCH] Update '2_Apps&BD' --- 2_Apps%26BD.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/2_Apps%26BD.md b/2_Apps%26BD.md index 0d74dd9..d76ef75 100644 --- a/2_Apps%26BD.md +++ b/2_Apps%26BD.md @@ -10,7 +10,7 @@ ### Modularización *ej. Proyecto1* -``` +```sh __________________________________ | Proyecto Tienda Online | | | @@ -26,7 +26,7 @@ ``` *ej. Proyecto2* -``` +```sh __________________________________ | Proy. Gestión Almacen | | | @@ -53,7 +53,7 @@ Creación primera app : ` python3 manage.py startapp gestionPedidos` */TiendaOnline/gestionPedidos/* -``` +```py - migrations/ - admin.py - apps.py @@ -66,7 +66,7 @@ Creación primera app : ` python3 manage.py startapp gestionPedidos` ### SQLite3 (default) */gestionPedidos/models.py* -``` +```py from django.db import models class Clientes(models.Model): @@ -87,7 +87,7 @@ class Pedidos (models.Model): ``` *settings.py* -``` +```py ... INSTALLED_APPS = [ ... @@ -96,12 +96,12 @@ INSTALLED_APPS = [ ... ``` ### Chequear código : -``` +```sh python3 manage.py check gestionPedidos ``` ### Creación del modelo Base de Datos : -``` +```sh python3 manage.py makemigrations # Ver instrucciones SQL @@ -110,7 +110,7 @@ python3 manage.py slqmigrate gestionPedidos 0001 ``` ### Creación de BD: -``` +```sh python3 manage.py migrate ``` @@ -118,7 +118,7 @@ python3 manage.py migrate ### Insertar Registros *(InteractiveConsole)* -``` +```py >>> from gestionPedidos.models import Articulos >>> >>> art = Articulos(nombre='mesa', seccion='decoracion', precio=96) @@ -132,14 +132,14 @@ python3 manage.py migrate ``` ### Actualizar Registros -``` +```py >>> art.precio=99 >>> art.save() >>> ``` ### Borrar Registros -``` +```py >>> art5 = Articulos.objects.get(id=2) >>> art5.delete() (1, {'gestionPedidos.Articulos': 1}) @@ -147,7 +147,7 @@ python3 manage.py migrate ``` ### Select -``` +```py >>> ResConsulta = Articulos.objects.all() >>> ResConsulta , ]> @@ -163,7 +163,7 @@ python3 manage.py migrate ## PostgreSQL ### Install -``` +```sh sudo apt install postgresql postgresql-contrib libpq-dev Success. You can now start the database server using: @@ -203,7 +203,7 @@ postgres@ratsat:~$ psql -U django -W ``` ### Problemas con Log-in ? -``` +```sh sudo vim /etc/postgresql/11/main/pg_hba.conf # CAMBIAR @@ -242,7 +242,7 @@ sudo ufw allow proto tcp from 192.168.0.0/24 to any port 5432 Usar algun DBbrowser y crear bd ArticulosClientes ### Instalar Python-Django PostgreSQL connector -``` +```sh pip3 install psycopg2 vim settings.py @@ -277,7 +277,7 @@ python3 manage.py makemigrations python3 manage.py migrate ``` ### Crear un registro -``` +```py python3 manage.py shell (InteractiveConsole) @@ -302,7 +302,7 @@ Valores en tabla articulos |8|tren eléctrico|juguetes|50| ### Intruccion SQL desde Django -``` +```py # Select * ... where seccion='deporte'; >>> from gestionPedidos.models import Articulos >>> @@ -312,7 +312,7 @@ Valores en tabla articulos ``` */TiendaOnline/gestionPedidos/models.py* -``` +```py class Articulos(models.Model): nombre = models.CharField(max_length=30) seccion = models.CharField(max_length=20) @@ -322,7 +322,7 @@ class Articulos(models.Model): return 'Nombre: %s, Depto. %s, Precio $ %s' % (self.nombre, self.seccion, self.precio) ``` -``` +```py python3 manage.py makemigrations python3 manage.py migrate python3 manage.py shell