-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into version-upgrades
- Loading branch information
Showing
17 changed files
with
168 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Count, Q | ||
|
||
from clubs.models import Club | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Update stored favorite and membership counts." | ||
|
||
def handle(self, *args, **kwargs): | ||
try: | ||
queryset = Club.objects.all().annotate( | ||
temp_favorite_count=Count("favorite", distinct=True), | ||
temp_membership_count=Count( | ||
"membership", distinct=True, filter=Q(active=True) | ||
), | ||
) | ||
|
||
for club in queryset: | ||
club.favorite_count = club.temp_favorite_count | ||
club.membership_count = club.temp_membership_count | ||
Club.objects.bulk_update(queryset, ["favorite_count", "membership_count"]) | ||
|
||
self.stdout.write( | ||
self.style.SUCCESS( | ||
"Successfully updated all club favorite and membership counts!" | ||
) | ||
) | ||
except Exception as e: | ||
self.stdout.write( | ||
self.style.ERROR( | ||
"An error was encountered while updating" | ||
+ "club favorite and membership counts!" | ||
) | ||
) | ||
self.stdout.write(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 3.2.18 on 2024-02-03 22:21 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("clubs", "0094_applicationcycle_release_date"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField(model_name="applicationsubmission", name="archived",), | ||
migrations.AddField( | ||
model_name="club", | ||
name="favorite_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="club", | ||
name="membership_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="historicalclub", | ||
name="favorite_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name="historicalclub", | ||
name="membership_count", | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.