From aa1a7189ae57f4b470929086f33dabf0c4ba073d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 4 Jan 2022 11:00:21 -0800 Subject: [PATCH] Uses function to get current year for annual goal default --- .../migrations/0122_alter_annualgoal_year.py | 19 +++++++++++++++++++ bookwyrm/models/user.py | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/migrations/0122_alter_annualgoal_year.py diff --git a/bookwyrm/migrations/0122_alter_annualgoal_year.py b/bookwyrm/migrations/0122_alter_annualgoal_year.py new file mode 100644 index 000000000..90af5fccf --- /dev/null +++ b/bookwyrm/migrations/0122_alter_annualgoal_year.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.5 on 2022-01-04 18:59 + +import bookwyrm.models.user +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0121_user_summary_keys"), + ] + + operations = [ + migrations.AlterField( + model_name="annualgoal", + name="year", + field=models.IntegerField(default=bookwyrm.models.user.get_current_year), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index deec2a441..bd340b01d 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -415,12 +415,17 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): return activity_object +def get_current_year(): + """sets default year for annual goal to this year""" + return timezone.now().year + + class AnnualGoal(BookWyrmModel): """set a goal for how many books you read in a year""" user = models.ForeignKey("User", on_delete=models.PROTECT) goal = models.IntegerField(validators=[MinValueValidator(1)]) - year = models.IntegerField(default=timezone.now().year) + year = models.IntegerField(default=get_current_year) privacy = models.CharField( max_length=255, default="public", choices=fields.PrivacyLevels.choices )