diff --git a/Procfile b/Procfile index 01e0e2f..a5ca7be 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -release: python manage.py migrate --noinput +deac web: gunicorn pypro.wsgi --log-file - \ No newline at end of file diff --git a/pypro/settings.py b/pypro/settings.py index 29a1aff..d61b91e 100644 --- a/pypro/settings.py +++ b/pypro/settings.py @@ -46,6 +46,7 @@ 'collectfast', 'django.contrib.staticfiles', 'pypro.base', + 'pypro.turmas', 'pypro.aperitivos', 'pypro.modulos', 'ordered_model', diff --git a/pypro/turmas/__init__.py b/pypro/turmas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypro/turmas/admin.py b/pypro/turmas/admin.py new file mode 100644 index 0000000..c08af5e --- /dev/null +++ b/pypro/turmas/admin.py @@ -0,0 +1,20 @@ +from django.contrib import admin + +# Register your models here. +from pypro.turmas.models import Turma + + +class MatriculaInline(admin.TabularInline): + model = Turma.alunos.through + extra = 1 + readonly_fields = ('data',) + autocomplete_fields = ('usuario',) + ordering = ('-data',) + + +@admin.register(Turma) +class TurmaAdmin(admin.ModelAdmin): + inlines = [MatriculaInline] + list_display = ('nome', 'slug', 'inicio', 'fim') + prepopulated_fields = {'slug': ('nome', )} + ordering = ('-inicio', ) diff --git a/pypro/turmas/apps.py b/pypro/turmas/apps.py new file mode 100644 index 0000000..3f536ce --- /dev/null +++ b/pypro/turmas/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TurmasConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "pypro.turmas" diff --git a/pypro/turmas/migrations/0001_initial.py b/pypro/turmas/migrations/0001_initial.py new file mode 100644 index 0000000..95beb2f --- /dev/null +++ b/pypro/turmas/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.6 on 2023-11-11 23:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Turma", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("nome", models.CharField(max_length=64)), + ("slug", models.SlugField(max_length=64)), + ("inicio", models.DateField()), + ("fim", models.DateField()), + ], + ), + ] diff --git a/pypro/turmas/migrations/0002_criacao_matricula.py b/pypro/turmas/migrations/0002_criacao_matricula.py new file mode 100644 index 0000000..6bfe793 --- /dev/null +++ b/pypro/turmas/migrations/0002_criacao_matricula.py @@ -0,0 +1,51 @@ +# Generated by Django 4.2.6 on 2023-11-12 00:22 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("turmas", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Matricula", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("data", models.DateTimeField(auto_now_add=True)), + ( + "turma", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="turmas.turma" + ), + ), + ( + "usuario", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.AddField( + model_name="turma", + name="alunos", + field=models.ManyToManyField( + through="turmas.Matricula", to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py b/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py new file mode 100644 index 0000000..86bfb9f --- /dev/null +++ b/pypro/turmas/migrations/0003_restricao_de_matricula_unica.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-11-12 00:33 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("turmas", "0002_criacao_matricula"), + ] + + operations = [ + migrations.AlterModelOptions( + name="matricula", + options={"ordering": ["turma", "data"]}, + ), + migrations.AlterUniqueTogether( + name="matricula", + unique_together={("usuario", "turma")}, + ), + ] diff --git a/pypro/turmas/migrations/__init__.py b/pypro/turmas/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypro/turmas/models.py b/pypro/turmas/models.py new file mode 100644 index 0000000..9a74319 --- /dev/null +++ b/pypro/turmas/models.py @@ -0,0 +1,20 @@ +from django.db import models +from django.contrib.auth import get_user_model + + +class Turma(models.Model): + nome = models.CharField(max_length=64) + slug = models.SlugField(max_length=64) + inicio = models.DateField() + fim = models.DateField() + alunos = models.ManyToManyField(get_user_model(), through='Matricula') + + +class Matricula(models.Model): + data = models.DateTimeField(auto_now_add=True) + usuario = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) + turma = models.ForeignKey(Turma, on_delete=models.CASCADE) + + class Meta: + unique_together = [['usuario', 'turma']] + ordering = ['turma', 'data'] diff --git a/pypro/turmas/templates/turmas/indice.html b/pypro/turmas/templates/turmas/indice.html new file mode 100644 index 0000000..9c5d18c --- /dev/null +++ b/pypro/turmas/templates/turmas/indice.html @@ -0,0 +1,28 @@ +{% extends 'base/base.html' %} +{% load static %} +{% block title %}Índice de turmas{% endblock title %} +{% block description %}Página com todas as turmas do curso Dev Pro {{modulo.titulo}}{% endblock description %} +{% block body %} +