Skip to content

Commit

Permalink
Add active to Emblem/Description
Browse files Browse the repository at this point in the history
- Added querysets to pull active/inactive only
- Updated ordering to give precedence to active items when calling objects.all
  • Loading branch information
Bekabyx committed Jul 3, 2023
1 parent e7e9f67 commit 76c53eb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 3 additions & 1 deletion wcivf/apps/parties/management/commands/import_parties.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def add_party_descriptions(self, party_obj, descriptions):
defaults={
"date_description_approved": description[
"date_description_approved"
]
],
"active": description["active"],
},
)

Expand All @@ -38,6 +39,7 @@ def add_party_emblems(self, party_obj, emblems):
"description": emblem["description"],
"date_approved": emblem["date_approved"],
"default": emblem["default"],
"active": emblem["active"],
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.1.6 on 2023-06-14 15:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("parties", "0018_alter_partydescription_options"),
]

operations = [
migrations.AlterModelOptions(
name="partydescription",
options={"ordering": ["-active", "date_description_approved"]},
),
migrations.AlterModelOptions(
name="partyemblem",
options={"ordering": ("-default", "-active", "ec_emblem_id")},
),
migrations.AddField(
model_name="partydescription",
name="active",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="partyemblem",
name="active",
field=models.BooleanField(default=False),
),
]
26 changes: 24 additions & 2 deletions wcivf/apps/parties/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def format_register(self):
return None


class PartyDescriptionQuerySet(models.QuerySet):
def active(self):
return self.filter(active=True)

def inactive(self):
return self.filter(active=False)


class PartyDescription(TimeStampedModel):
"""
A party can register one or more descriptions with The Electoral Commission.
Expand All @@ -182,14 +190,25 @@ class PartyDescription(TimeStampedModel):

description = models.CharField(max_length=800)
date_description_approved = models.DateField(null=True)
active = models.BooleanField(default=False)

objects = PartyDescriptionQuerySet.as_manager()

class Meta:
unique_together = (
"party",
"description",
)

ordering = ["date_description_approved"]
ordering = ["-active", "date_description_approved"]


class PartyEmblemQuerySet(models.QuerySet):
def active(self):
return self.filter(active=True)

def inactive(self):
return self.filter(active=False)


class PartyEmblem(TimeStampedModel):
Expand All @@ -201,9 +220,12 @@ class PartyEmblem(TimeStampedModel):
description = models.CharField(max_length=255)
date_approved = models.DateField(null=True)
default = models.BooleanField(default=False)
active = models.BooleanField(default=False)

objects = PartyEmblemQuerySet.as_manager()

class Meta:
ordering = ("-default", "ec_emblem_id")
ordering = ("-default", "-active", "ec_emblem_id")


class LocalParty(TimeStampedModel):
Expand Down

0 comments on commit 76c53eb

Please sign in to comment.