Skip to content

back nuevo y completo para usar con web y app #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: Developer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ricco/Doc-DB/DER RICCO.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed ricco/Doc-DB/DER RICCO_APP 2024.drawio.png
Binary file not shown.
Binary file removed ricco/Doc-DB/MODELO RELACIONAL RICCO.png
Binary file not shown.
Binary file modified ricco/ricco/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions ricco/ricco/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '10.0.2.2']

# ALLOWED_HOSTS = []

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down
2 changes: 1 addition & 1 deletion ricco/ricco/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
path('admin/', admin.site.urls),
# Api routers
path('api/', include('ricco_app.urls')),

# path('api/', include(router.urls)),
path('api/', include('rest_framework.urls')),

]
Binary file modified ricco/ricco_app/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified ricco/ricco_app/__pycache__/views.cpython-311.pyc
Binary file not shown.
24 changes: 20 additions & 4 deletions ricco/ricco_app/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin

from .models import Producto
from .models import Direccion

from .models import Compra
from .models import Detalle
from .models import Pedido

# Register your models here.
@admin.register(get_user_model())
Expand All @@ -23,16 +26,29 @@ class CustomUserAdmin(UserAdmin):
list_display = ('email', 'first_name', 'last_name', 'rol','is_staff') #10/10 agregue rol
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)



class RolAdmin(admin.ModelAdmin):
list_display = ('id_rol','nombre_rol')

class ProductoAdmin(admin.ModelAdmin):
list_display = ('id_producto', 'nombre_producto', 'descripcion', 'precio')

class DireccionAdmin(admin.ModelAdmin):
list_display = ('id_direccion', 'calle', 'numero')

class CompraAdmin(admin.ModelAdmin):
list_display = ('id_compra', 'fecha', 'precio_total')

class DetalleAdmin(admin.ModelAdmin):
list_display = ('id_detalle', 'cantidad', 'precio_calculado')

class PedidoAdmin(admin.ModelAdmin):
list_display = ('id_pedido', 'fecha_pedido', 'estado')



admin.site.register(Direccion, DireccionAdmin)
admin.site.register(Producto, ProductoAdmin)

admin.site.register(Compra, CompraAdmin)
admin.site.register(Detalle, DetalleAdmin)
admin.site.register(Pedido, PedidoAdmin)
98 changes: 78 additions & 20 deletions ricco/ricco_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 4.2 on 2024-09-14 19:55
# Generated by Django 4.2 on 2024-11-25 22:10

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
Expand All @@ -14,6 +15,43 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='CustomUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('email', models.EmailField(max_length=150, unique=True)),
('telefono', models.CharField(blank=True, max_length=50, null=True)),
('rol', models.CharField(choices=[('admin', 'Admin'), ('cliente', 'Cliente')], default='cliente', max_length=10)),
],
options={
'verbose_name': 'Usuario',
'verbose_name_plural': 'Usuarios',
'db_table': 'usuario',
},
),
migrations.CreateModel(
name='Compra',
fields=[
('id_compra', models.AutoField(primary_key=True, serialize=False)),
('fecha', models.DateField(auto_now_add=True)),
('descripcion', models.TextField(default='', max_length=1000)),
('precio_total', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
('user', models.ForeignKey(blank=True, default='', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compra', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Compra',
'verbose_name_plural': 'Compras',
'db_table': 'compra',
},
),
migrations.CreateModel(
name='Direccion',
fields=[
Expand All @@ -34,6 +72,7 @@ class Migration(migrations.Migration):
('nombre_producto', models.CharField(default='', max_length=100)),
('descripcion', models.TextField(default='', max_length=255)),
('precio', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
('is_in_stock', models.BooleanField(default=True)),
],
options={
'verbose_name': 'Producto',
Expand All @@ -42,28 +81,47 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='CustomUser',
name='Pedido',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('username', models.CharField(blank=True, max_length=150, null=True, unique=True)),
('email', models.EmailField(max_length=150, unique=True)),
('telefono', models.CharField(blank=True, max_length=50, null=True)),
('direccion', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='usuario', to='ricco_app.direccion')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
('id_pedido', models.AutoField(primary_key=True, serialize=False)),
('fecha_pedido', models.DateField(auto_now_add=True)),
('estado', models.CharField(default='', max_length=50)),
('user', models.ForeignKey(blank=True, default='', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pedido', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Usuario',
'verbose_name_plural': 'Usuarios',
'db_table': 'usuario',
'verbose_name': 'Pedido',
'verbose_name_plural': 'Pedidos',
'db_table': 'Pedido',
},
),
migrations.CreateModel(
name='Detalle',
fields=[
('id_detalle', models.AutoField(primary_key=True, serialize=False)),
('cantidad', models.IntegerField(default=1)),
('precio_calculado', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
('compra', models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, related_name='detalle', to='ricco_app.compra')),
('producto', models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, related_name='detalle', to='ricco_app.producto')),
],
options={
'verbose_name': 'Detalle',
'verbose_name_plural': 'Detalles',
'db_table': 'detalle',
},
),
migrations.AddField(
model_name='customuser',
name='direccion',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='usuario', to='ricco_app.direccion'),
),
migrations.AddField(
model_name='customuser',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups'),
),
migrations.AddField(
model_name='customuser',
name='user_permissions',
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions'),
),
]

This file was deleted.

18 changes: 0 additions & 18 deletions ricco/ricco_app/migrations/0003_producto_is_in_stock.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified ricco/ricco_app/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
59 changes: 53 additions & 6 deletions ricco/ricco_app/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.conf import settings
from django.contrib.auth.models import AbstractUser, BaseUserManager


# Modelo de Producto
class Producto(models.Model):
id_producto = models.AutoField(primary_key=True)
Expand All @@ -18,8 +18,8 @@ class Meta:

def __str__(self):
return str(self.nombre_producto)


# Modelo de Dirección
class Direccion(models.Model):
id_direccion = models.AutoField(primary_key=True)
Expand All @@ -33,7 +33,7 @@ class Meta:

def __str__(self):
return f"{self.calle}, {self.numero}"


# Manager de Usuario Personalizado
class CustomUserManager(BaseUserManager):
Expand All @@ -55,8 +55,7 @@ def create_superuser(self, email, password=None, **extra_fields):
user.rol = 'admin' # Asegúrate de asignar el rol correcto
user.save(using=self._db)
return user



# Modelo de Usuario Personalizado
class CustomUser(AbstractUser):
username = None # Esto elimina el campo username
Expand All @@ -77,4 +76,52 @@ class Meta:

def __str__(self):
return self.email



class Compra(models.Model):
id_compra = models.AutoField(primary_key=True)
fecha = models.DateField(auto_now_add=True)
descripcion = models.TextField(max_length=1000, blank=False, default='')
precio_total = models.DecimalField(max_digits=10, decimal_places=2, blank=False, default=0.0)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True, related_name="compra", default="")

class Meta:
db_table = 'compra'
verbose_name = 'Compra'
verbose_name_plural = 'Compras'

def __str__(self):
return str(self.id_compra)


class Detalle(models.Model):
id_detalle = models.AutoField(primary_key=True)
cantidad = models.IntegerField(blank=False, default=1)
precio_calculado = models.DecimalField(max_digits=10, decimal_places=2, blank=False, default=0.0)
producto = models.ForeignKey(Producto, to_field='id_producto', on_delete=models.CASCADE, related_name="detalle", default="")
compra = models.ForeignKey(Compra, to_field='id_compra', on_delete=models.CASCADE, related_name="detalle", default="")

class Meta:
db_table = 'detalle'
verbose_name = 'Detalle'
verbose_name_plural = 'Detalles'

def __str__(self):
return f"{self.cantidad}, {self.precio_calculado}"


class Pedido(models.Model):
id_pedido = models.AutoField(primary_key=True)
fecha_pedido = models.DateField(auto_now_add=True)
estado = models.CharField(max_length=50, blank=False, default='')
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True, related_name="pedido", default="")


class Meta:
db_table = 'Pedido'
verbose_name = 'Pedido'
verbose_name_plural = 'Pedidos'

def __str__(self):
return str(self.id_pedido)
3 changes: 1 addition & 2 deletions ricco/ricco_app/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
# class IsAdminOnly(permissions.BasePermission):
# def has_permission(self, request, view):

# return request.user and request.user.is_staff

# return request.user and request.user.is_staff
Loading