Make rating a decimal field

This commit is contained in:
Mouse Reeve 2021-03-19 12:14:59 -07:00
parent 5f1bed3d78
commit 266c6fe777
3 changed files with 27 additions and 1 deletions

View file

@ -0,0 +1,20 @@
# Generated by Django 3.1.6 on 2021-03-19 19:13
import bookwyrm.models.fields
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0052_user_show_goal'),
]
operations = [
migrations.AlterField(
model_name='review',
name='rating',
field=bookwyrm.models.fields.DecimalField(blank=True, decimal_places=2, default=None, max_digits=3, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(5)]),
),
]

View file

@ -444,3 +444,7 @@ class BooleanField(ActivitypubFieldMixin, models.BooleanField):
class IntegerField(ActivitypubFieldMixin, models.IntegerField): class IntegerField(ActivitypubFieldMixin, models.IntegerField):
""" activitypub-aware boolean field """ """ activitypub-aware boolean field """
class DecimalField(ActivitypubFieldMixin, models.DecimalField):
""" activitypub-aware boolean field """

View file

@ -273,11 +273,13 @@ class Review(Status):
book = fields.ForeignKey( book = fields.ForeignKey(
"Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook" "Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook"
) )
rating = fields.IntegerField( rating = fields.DecimalField(
default=None, default=None,
null=True, null=True,
blank=True, blank=True,
validators=[MinValueValidator(1), MaxValueValidator(5)], validators=[MinValueValidator(1), MaxValueValidator(5)],
decimal_places=2,
max_digits=3,
) )
@property @property