diff --git a/ExEcommerce/__pycache__/__init__.cpython-39.pyc b/ExEcommerce/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..24c4e20 Binary files /dev/null and b/ExEcommerce/__pycache__/__init__.cpython-39.pyc differ diff --git a/ExEcommerce/__pycache__/settings.cpython-39.pyc b/ExEcommerce/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000..4cd18ab Binary files /dev/null and b/ExEcommerce/__pycache__/settings.cpython-39.pyc differ diff --git a/ExEcommerce/__pycache__/urls.cpython-39.pyc b/ExEcommerce/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..db5162b Binary files /dev/null and b/ExEcommerce/__pycache__/urls.cpython-39.pyc differ diff --git a/ExEcommerce/__pycache__/wsgi.cpython-39.pyc b/ExEcommerce/__pycache__/wsgi.cpython-39.pyc new file mode 100644 index 0000000..5c3d525 Binary files /dev/null and b/ExEcommerce/__pycache__/wsgi.cpython-39.pyc differ diff --git a/ExEcommerce/settings.py b/ExEcommerce/settings.py index 16bb888..5c5cb61 100644 --- a/ExEcommerce/settings.py +++ b/ExEcommerce/settings.py @@ -38,6 +38,7 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'Productos', + 'checkout1073246233', 'rest_framework', 'rest_framework.authtoken', 'Checkout', diff --git a/ExEcommerce/urls.py b/ExEcommerce/urls.py index 3b6ef59..f6c828f 100644 --- a/ExEcommerce/urls.py +++ b/ExEcommerce/urls.py @@ -4,5 +4,9 @@ urlpatterns = [ path('admin/', admin.site.urls), path('productos/api/', include('Productos.urls')), + + path('checkout/api/',include('checkout1073246233.urls')), + path('checkout/api/', include('Checkout.urls')) + ] diff --git a/Productos/__pycache__/__init__.cpython-39.pyc b/Productos/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..38e5c94 Binary files /dev/null and b/Productos/__pycache__/__init__.cpython-39.pyc differ diff --git a/Productos/__pycache__/admin.cpython-39.pyc b/Productos/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..4166ef8 Binary files /dev/null and b/Productos/__pycache__/admin.cpython-39.pyc differ diff --git a/Productos/__pycache__/apps.cpython-39.pyc b/Productos/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000..d68e7d3 Binary files /dev/null and b/Productos/__pycache__/apps.cpython-39.pyc differ diff --git a/Productos/__pycache__/models.cpython-39.pyc b/Productos/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..2d93477 Binary files /dev/null and b/Productos/__pycache__/models.cpython-39.pyc differ diff --git a/Productos/__pycache__/serializers.cpython-39.pyc b/Productos/__pycache__/serializers.cpython-39.pyc new file mode 100644 index 0000000..7ef2360 Binary files /dev/null and b/Productos/__pycache__/serializers.cpython-39.pyc differ diff --git a/Productos/__pycache__/urls.cpython-39.pyc b/Productos/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..3bc4930 Binary files /dev/null and b/Productos/__pycache__/urls.cpython-39.pyc differ diff --git a/Productos/__pycache__/views.cpython-39.pyc b/Productos/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..55a8b1e Binary files /dev/null and b/Productos/__pycache__/views.cpython-39.pyc differ diff --git a/Productos/migrations/__pycache__/0001_initial.cpython-39.pyc b/Productos/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000..bfb3b91 Binary files /dev/null and b/Productos/migrations/__pycache__/0001_initial.cpython-39.pyc differ diff --git a/Productos/migrations/__pycache__/0002_auto_20210916_1521.cpython-39.pyc b/Productos/migrations/__pycache__/0002_auto_20210916_1521.cpython-39.pyc new file mode 100644 index 0000000..c3efffe Binary files /dev/null and b/Productos/migrations/__pycache__/0002_auto_20210916_1521.cpython-39.pyc differ diff --git a/Productos/migrations/__pycache__/__init__.cpython-39.pyc b/Productos/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..cd46f95 Binary files /dev/null and b/Productos/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/checkout1073246233/__init__.py b/checkout1073246233/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/checkout1073246233/__pycache__/__init__.cpython-39.pyc b/checkout1073246233/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..c19e411 Binary files /dev/null and b/checkout1073246233/__pycache__/__init__.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/admin.cpython-39.pyc b/checkout1073246233/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..3512439 Binary files /dev/null and b/checkout1073246233/__pycache__/admin.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/apps.cpython-39.pyc b/checkout1073246233/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000..c920839 Binary files /dev/null and b/checkout1073246233/__pycache__/apps.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/models.cpython-39.pyc b/checkout1073246233/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..633661b Binary files /dev/null and b/checkout1073246233/__pycache__/models.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/serializers.cpython-39.pyc b/checkout1073246233/__pycache__/serializers.cpython-39.pyc new file mode 100644 index 0000000..28afa2f Binary files /dev/null and b/checkout1073246233/__pycache__/serializers.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/urls.cpython-39.pyc b/checkout1073246233/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..518aab3 Binary files /dev/null and b/checkout1073246233/__pycache__/urls.cpython-39.pyc differ diff --git a/checkout1073246233/__pycache__/views.cpython-39.pyc b/checkout1073246233/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..ebb54fb Binary files /dev/null and b/checkout1073246233/__pycache__/views.cpython-39.pyc differ diff --git a/checkout1073246233/admin.py b/checkout1073246233/admin.py new file mode 100644 index 0000000..4856412 --- /dev/null +++ b/checkout1073246233/admin.py @@ -0,0 +1,11 @@ +from django.contrib import admin +from .models import * +# Register your models here. +admin.site.register(CarritoCompras) +admin.site.register(Articulo) +admin.site.register(InfoEnvio) + +''' +usuario = juand +contra = 123 +''' \ No newline at end of file diff --git a/checkout1073246233/apps.py b/checkout1073246233/apps.py new file mode 100644 index 0000000..9e824a0 --- /dev/null +++ b/checkout1073246233/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class Checkout1073246233Config(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'checkout1073246233' diff --git a/checkout1073246233/migrations/0001_initial.py b/checkout1073246233/migrations/0001_initial.py new file mode 100644 index 0000000..a7408a1 --- /dev/null +++ b/checkout1073246233/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# Generated by Django 3.2.7 on 2021-09-21 02:54 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('Productos', '0002_auto_20210916_1521'), + ] + + operations = [ + migrations.CreateModel( + name='CarritoCompras', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('usuario', models.CharField(max_length=100)), + ('fecha', models.DateField(auto_now_add=True)), + ('dcto', models.FloatField(default=0)), + ('cantMinima', models.IntegerField(default=0)), + ('pagado', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='InfoEnvio', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nombre', models.CharField(max_length=100)), + ('apellido', models.CharField(max_length=100)), + ('direccion', models.CharField(max_length=200)), + ('pais', models.CharField(max_length=200)), + ('departamento', models.CharField(max_length=200)), + ('ciudad', models.CharField(max_length=200)), + ('carrito', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='checkout1073246233.carritocompras')), + ], + ), + migrations.CreateModel( + name='Articulo', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('cantidad', models.IntegerField(default=0)), + ('carrito', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='checkout1073246233.carritocompras')), + ('producto', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='Productos.producto')), + ], + ), + ] diff --git a/checkout1073246233/migrations/__init__.py b/checkout1073246233/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/checkout1073246233/migrations/__pycache__/0001_initial.cpython-39.pyc b/checkout1073246233/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000..bb3e567 Binary files /dev/null and b/checkout1073246233/migrations/__pycache__/0001_initial.cpython-39.pyc differ diff --git a/checkout1073246233/migrations/__pycache__/__init__.cpython-39.pyc b/checkout1073246233/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..0199101 Binary files /dev/null and b/checkout1073246233/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/checkout1073246233/models.py b/checkout1073246233/models.py new file mode 100644 index 0000000..b71fa2b --- /dev/null +++ b/checkout1073246233/models.py @@ -0,0 +1,48 @@ +from django.db import models +from Productos.models import Producto +# Create your models here. + +class CarritoCompras(models.Model): + usuario = models.CharField(max_length=100) + fecha = models.DateField(auto_now_add=True) + dcto = models.FloatField(default=0) + cantMinima = models.IntegerField(default=0) + pagado = models.BooleanField(default=False) + + def __str__(self): + return self.usuario+' - '+str(self.fecha) + + def total(self): + total = 0 + articuloscarro = self.articulo_set.all() + for articulo in articuloscarro: + total += articulo.subtotal() + return total + @property + def numArt(self): + articulos = self.articulo_set.all() + return len(articulos) + +class Articulo(models.Model): + carrito = models.ForeignKey(CarritoCompras,on_delete=models.CASCADE) + producto = models.ForeignKey(Producto,on_delete=models.SET_NULL,null=True) + cantidad = models.IntegerField(default=0) + + def __str__(self): + return self.carrito.__str__()+' / '+self.producto.__str__() + + def subtotal(self): + return self.producto.precio*self.cantidad + + +class InfoEnvio(models.Model): + carrito = models.ForeignKey(CarritoCompras,on_delete=models.CASCADE) + nombre = models.CharField(max_length=100) + apellido = models.CharField(max_length=100) + direccion = models.CharField(max_length=200) + pais = models.CharField(max_length=200) + departamento = models.CharField(max_length=200) + ciudad = models.CharField(max_length=200) + + def __str__(self): + return self.carrito.__str__() \ No newline at end of file diff --git a/checkout1073246233/serializers.py b/checkout1073246233/serializers.py new file mode 100644 index 0000000..f5703b1 --- /dev/null +++ b/checkout1073246233/serializers.py @@ -0,0 +1,17 @@ +from .models import * +from rest_framework import serializers + +class CarritoComprasSerial(serializers.ModelSerializer): + class Meta : + model = CarritoCompras + fields ='__all__' + +class ArticuloSerial(serializers.ModelSerializer): + class Meta: + model = Articulo + fields = '__all__' + +class InfoSerial(serializers.ModelSerializer): + class Meta: + model = InfoEnvio + fields = '__all__' \ No newline at end of file diff --git a/checkout1073246233/tests.py b/checkout1073246233/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/checkout1073246233/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/checkout1073246233/urls.py b/checkout1073246233/urls.py new file mode 100644 index 0000000..bec5ba4 --- /dev/null +++ b/checkout1073246233/urls.py @@ -0,0 +1,15 @@ +from django.urls import path,include +from rest_framework import urlpatterns + +from rest_framework.routers import DefaultRouter +from checkout1073246233.views import * + +router = DefaultRouter() + +router.register('carrito',CarritoComprasAPI,basename='Carrito') +router.register('articulos',ArticulosAPI,basename='Articulo') +router.register('infoenvio',InfoAPI,basename='Info') + +urlpatterns = [ + path('crud/',include(router.urls)) +] \ No newline at end of file diff --git a/checkout1073246233/views.py b/checkout1073246233/views.py new file mode 100644 index 0000000..702ca81 --- /dev/null +++ b/checkout1073246233/views.py @@ -0,0 +1,68 @@ +from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework.status import HTTP_400_BAD_REQUEST + +from checkout1073246233.serializers import * +from checkout1073246233.models import * + +class CarritoComprasAPI(viewsets.ViewSet): + def list(self, request): + carritos = CarritoCompras.objects.all() + serializer = CarritoComprasSerial(carritos, many=True) + return Response(serializer.data) + + def create(self, request): + serializer = CarritoComprasSerial(data=request.data) + if serializer.is_valid(): + carrito = serializer.save() + return Response({'idCarrito':carrito.id}) + return Response(serializer.errors, HTTP_400_BAD_REQUEST) + def retrieve(self, request, pk=None): + #Obtener uno o varios objetos de la base de datos + #pk -> llave primaria - metodo de identificacion de objetos + carritos = CarritoCompras.objects.get(pk=pk) + serializador = CarritoComprasSerial(carritos) + return Response(serializador.data) + + def partial_update(self, request, pk=None): + carrito = self.get_object() + data = {'pagado':True} + serializer = CarritoComprasSerial(carrito, data, partial=True) + if serializer.is_valid(): + serializer.save() + return Response({'update':True}) + return Response(serializer.errors, HTTP_400_BAD_REQUEST) + +class ArticulosAPI(viewsets.ViewSet): + def list(self, request): + articulos = Articulo.objects.all() + serializer = ArticuloSerial(articulos, many=True) + return Response(serializer.data) + + def create(self, request): + serializer = ArticuloSerial(data=request.data, many=True) + if serializer.is_valid(): + serializer.save() + return Response({'Creados':True}) + return Response(serializer.errors, HTTP_400_BAD_REQUEST) + + def retrieve(self,requets,pk=None): + articulos = Articulo.objects.get(pk=pk) + serializador = ArticuloSerial(articulos) + return Response(serializador.data) + +class InfoAPI(viewsets.ViewSet): + def list(self,request): + info = InfoEnvio.objects.all() + serializador = InfoSerial(info,many=True) + return Response(serializador.data) + + def create(self,request): + serializador = InfoSerial(data = request.data) + if serializador.is_valid(): + serializador.save() + return Response({'DatosListos':True}) + return Response(serializador.errors) + + def partial_update(): + pass \ No newline at end of file