mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-08-25 11:33:17 +02:00
Inicio del Django y base de datos
This commit is contained in:
parent
57494f02e5
commit
0e0c8d7d1b
66 changed files with 647 additions and 69 deletions
0
Plataform_Web/temporadas/__init__.py
Normal file
0
Plataform_Web/temporadas/__init__.py
Normal file
BIN
Plataform_Web/temporadas/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
Plataform_Web/temporadas/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
Plataform_Web/temporadas/__pycache__/admin.cpython-314.pyc
Normal file
BIN
Plataform_Web/temporadas/__pycache__/admin.cpython-314.pyc
Normal file
Binary file not shown.
BIN
Plataform_Web/temporadas/__pycache__/apps.cpython-314.pyc
Normal file
BIN
Plataform_Web/temporadas/__pycache__/apps.cpython-314.pyc
Normal file
Binary file not shown.
BIN
Plataform_Web/temporadas/__pycache__/models.cpython-314.pyc
Normal file
BIN
Plataform_Web/temporadas/__pycache__/models.cpython-314.pyc
Normal file
Binary file not shown.
13
Plataform_Web/temporadas/admin.py
Normal file
13
Plataform_Web/temporadas/admin.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from django.contrib import admin
|
||||
from .models import Temporada
|
||||
|
||||
@admin.register(Temporada)
|
||||
class TemporadaAdmin(admin.ModelAdmin):
|
||||
# Esto define qué columnas se ven en la lista
|
||||
list_display = ('nombre', 'fecha_inicio', 'fecha_fin', 'presupuesto', 'actual')
|
||||
|
||||
# Esto añade un filtro a la derecha para ver rápido cuál es la actual
|
||||
list_filter = ('actual',)
|
||||
|
||||
# Esto añade una barra de búsqueda por nombre
|
||||
search_fields = ('nombre',)
|
||||
5
Plataform_Web/temporadas/apps.py
Normal file
5
Plataform_Web/temporadas/apps.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TemporadasConfig(AppConfig):
|
||||
name = 'temporadas'
|
||||
30
Plataform_Web/temporadas/migrations/0001_initial.py
Normal file
30
Plataform_Web/temporadas/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 6.0.2 on 2026-02-17 11:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Temporada',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('nombre', models.CharField(max_length=50, unique=True)),
|
||||
('fecha_inicio', models.DateField()),
|
||||
('fecha_fin', models.DateField()),
|
||||
('presupuesto', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
|
||||
('actual', models.BooleanField(default=False, verbose_name='¿Es la temporada actual?')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Temporada',
|
||||
'verbose_name_plural': 'Temporadas',
|
||||
'ordering': ['-fecha_inicio'],
|
||||
},
|
||||
),
|
||||
]
|
||||
0
Plataform_Web/temporadas/migrations/__init__.py
Normal file
0
Plataform_Web/temporadas/migrations/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
30
Plataform_Web/temporadas/models.py
Normal file
30
Plataform_Web/temporadas/models.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from django.db import models
|
||||
|
||||
class Temporada(models.Model):
|
||||
# El nombre será algo como "Gades 2024-25"
|
||||
nombre = models.CharField(max_length=50, unique=True)
|
||||
|
||||
fecha_inicio = models.DateField()
|
||||
fecha_fin = models.DateField()
|
||||
|
||||
# Presupuesto total para ese año
|
||||
presupuesto = models.DecimalField(max_digits=10, decimal_places=2, default=0.00)
|
||||
|
||||
# Checkbox para marcar cuál es la temporada que estamos viviendo ahora
|
||||
actual = models.BooleanField(default=False, verbose_name="¿Es la temporada actual?")
|
||||
|
||||
class Meta:
|
||||
# Esto es para que en el panel salga "Temporadas" y no "Temporadas"
|
||||
verbose_name = "Temporada"
|
||||
verbose_name_plural = "Temporadas"
|
||||
ordering = ['-fecha_inicio'] # Ordena las más nuevas primero
|
||||
|
||||
def __str__(self):
|
||||
return self.nombre
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# TRUCO PRO: Si marco esta temporada como "actual", desmarco todas las demás
|
||||
# Así evitamos que haya dos temporadas activas a la vez.
|
||||
if self.actual:
|
||||
Temporada.objects.filter(actual=True).exclude(pk=self.pk).update(actual=False)
|
||||
super().save(*args, **kwargs)
|
||||
3
Plataform_Web/temporadas/tests.py
Normal file
3
Plataform_Web/temporadas/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
Plataform_Web/temporadas/views.py
Normal file
3
Plataform_Web/temporadas/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Loading…
Add table
Add a link
Reference in a new issue