Skip to content

Commit

Permalink
feat(vote): Created a election status model
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomario committed Oct 7, 2024
1 parent 601d4f2 commit ad0ec16
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2 on 2024-10-07 22:04

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('candidature', '0022_alter_candidature_ballot_name_and_more'),
]

operations = [
migrations.CreateModel(
name='ElectionResult',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('year', models.PositiveIntegerField(verbose_name='Ano da eleição')),
('status', models.CharField(choices=[('eleita', 'Eleita/o'), ('segundo_turno', 'Segundo Turno'), ('nao_eleito', 'Não Eleita/o')], max_length=20, verbose_name='Status da eleição')),
('candidature', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='election_results', to='candidature.candidature')),
],
),
]
19 changes: 10 additions & 9 deletions app/org_eleicoes/votepeloclima/candidature/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ class Candidature(models.Model):
created_at = models.DateTimeField(verbose_name="Criado em", auto_now_add=True, null=True, blank=True)
updated_at = models.DateTimeField(verbose_name="Atualizado em", auto_now=True, null=True, blank=True)

election_status = models.CharField(
max_length=20,
choices=ElectionStatus.choices,
blank=True,
null=True,
verbose_name="Status da Eleição"
)
election_year = models.PositiveIntegerField(blank=True, null=True, verbose_name="Ano da Eleição")

class Meta:
verbose_name = "Candidatura"
ordering = ["-updated_at"]
Expand Down Expand Up @@ -113,13 +104,23 @@ def get_proposes_items(self):

return proposes_list

@property
def get_election_result(self, year):
return self.election_results.filter(year=year).first()


def save(self, *args, **kwargs):
if not self.slug:
self.slug = f"{slugify(self.ballot_name)}-{self.number_id}"
super().save(*args, **kwargs)


class ElectionResult(models.Model):
candidature = models.ForeignKey('Candidature', on_delete=models.CASCADE, related_name='election_results')
year = models.PositiveIntegerField(verbose_name="Ano da eleição")
status = models.CharField(max_length=20, choices=ElectionStatus.choices, verbose_name="Status da eleição")


class CandidatureFlow(models.Model):
# Propriedades só podem ser editadas quando status for `draft`
photo = models.ImageField(upload_to="candidatures/photos/", null=True, verbose_name="Foto")
Expand Down

0 comments on commit ad0ec16

Please sign in to comment.