From 1cd518023bb41ce20b1a8a42a7a0509ccac48fcb Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Mon, 2 Sep 2024 18:58:01 -0300 Subject: [PATCH] fix(vote): add updated and created fields and ordering suffle queryset to candidature list --- .../votepeloclima/candidature/admin.py | 6 ++- ...options_candidature_created_at_and_more.py | 40 +++++++++++++++++++ .../votepeloclima/candidature/models.py | 9 +++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/org_eleicoes/votepeloclima/candidature/migrations/0016_alter_candidature_options_candidature_created_at_and_more.py diff --git a/app/org_eleicoes/votepeloclima/candidature/admin.py b/app/org_eleicoes/votepeloclima/candidature/admin.py index 14412572..515e14e4 100644 --- a/app/org_eleicoes/votepeloclima/candidature/admin.py +++ b/app/org_eleicoes/votepeloclima/candidature/admin.py @@ -7,7 +7,8 @@ class CandidatureAdmin(admin.ModelAdmin): search_fields = ("legal_name", "ballot_name", "email", "political_party") - list_display = ("legal_name", "email", "political_party", "status") + list_display = ("legal_name", "email", "political_party", "status", "updated_at") + ordering = ("updated_at", ) def has_add_permission(self, request): return False @@ -51,7 +52,8 @@ class Meta: class CandidatureFlowAdmin(admin.ModelAdmin): form = CandidatureFlowAdminForm list_filter = ("status", ) - list_display = ("legal_name", "email", "political_party", "status") + list_display = ("legal_name", "email", "political_party", "status", "created_at", "updated_at") + ordering = ("updated_at", ) fieldsets = ( (None, { diff --git a/app/org_eleicoes/votepeloclima/candidature/migrations/0016_alter_candidature_options_candidature_created_at_and_more.py b/app/org_eleicoes/votepeloclima/candidature/migrations/0016_alter_candidature_options_candidature_created_at_and_more.py new file mode 100644 index 00000000..e1b52296 --- /dev/null +++ b/app/org_eleicoes/votepeloclima/candidature/migrations/0016_alter_candidature_options_candidature_created_at_and_more.py @@ -0,0 +1,40 @@ +# Generated by Django 4.2 on 2024-09-02 21:56 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('candidature', '0015_alter_candidature_appointments_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='candidature', + options={'ordering': ['?'], 'verbose_name': 'Candidatura'}, + ), + migrations.AddField( + model_name='candidature', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Criado em'), + preserve_default=False, + ), + migrations.AddField( + model_name='candidature', + name='updated_at', + field=models.DateTimeField(auto_now=True, verbose_name='Atualizado em'), + ), + migrations.AddField( + model_name='candidatureflow', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Criado em'), + preserve_default=False, + ), + migrations.AddField( + model_name='candidatureflow', + name='updated_at', + field=models.DateTimeField(auto_now=True, verbose_name='Atualizado em'), + ), + ] diff --git a/app/org_eleicoes/votepeloclima/candidature/models.py b/app/org_eleicoes/votepeloclima/candidature/models.py index 58c1d654..205f9422 100644 --- a/app/org_eleicoes/votepeloclima/candidature/models.py +++ b/app/org_eleicoes/votepeloclima/candidature/models.py @@ -41,8 +41,13 @@ class Candidature(models.Model): # friendly url by ballot_name slug = models.SlugField(max_length=100, unique=True, blank=True, null=True) + # + created_at = models.DateTimeField(verbose_name="Criado em", auto_now_add=True) + updated_at = models.DateTimeField(verbose_name="Atualizado em", auto_now=True) + class Meta: verbose_name = "Candidatura" + ordering = ["-updated_at"] @property def status(self): @@ -123,6 +128,10 @@ class CandidatureFlow(models.Model): # - Habilitar usuário `is_active=True` user = models.OneToOneField(User, null=True, on_delete=models.SET_NULL, verbose_name="Usuário") + # + created_at = models.DateTimeField(verbose_name="Criado em", auto_now_add=True) + updated_at = models.DateTimeField(verbose_name="Atualizado em", auto_now=True) + class Meta: verbose_name = "Formulário"