diff --git a/bookwyrm/migrations/0038_auto_20210119_1534.py b/bookwyrm/migrations/0038_auto_20210119_1534.py new file mode 100644 index 00000000..ac7a0d68 --- /dev/null +++ b/bookwyrm/migrations/0038_auto_20210119_1534.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2021-01-19 15:34 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0037_auto_20210118_1954'), + ] + + operations = [ + migrations.AlterField( + model_name='annualgoal', + name='goal', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1)]), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 1e9db401..79d11206 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -4,6 +4,7 @@ from urllib.parse import urlparse from django.apps import apps from django.contrib.auth.models import AbstractUser +from django.core.validators import MinValueValidator from django.db import models from django.dispatch import receiver from django.utils import timezone @@ -226,7 +227,9 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): 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() + goal = models.IntegerField( + validators=[MinValueValidator(1)] + ) year = models.IntegerField(default=timezone.now().year) privacy = models.CharField( max_length=255, diff --git a/bookwyrm/templates/snippets/goal_form.html b/bookwyrm/templates/snippets/goal_form.html index bd36f609..475c5da5 100644 --- a/bookwyrm/templates/snippets/goal_form.html +++ b/bookwyrm/templates/snippets/goal_form.html @@ -8,7 +8,7 @@
- +
diff --git a/bookwyrm/views/goal.py b/bookwyrm/views/goal.py index 45fe614b..f1954672 100644 --- a/bookwyrm/views/goal.py +++ b/bookwyrm/views/goal.py @@ -52,7 +52,7 @@ class Goal(View): form = forms.GoalForm(request.POST, instance=goal) if not form.is_valid(): data = { - 'title': '%s\'s %d Reading' % (goal.user.display_name, year), + 'title': '%s\'s %d Reading' % (request.user.display_name, year), 'goal_form': form, 'goal': goal, 'year': year,