From: Radek Czajka Date: Tue, 23 May 2023 10:15:15 +0000 (+0200) Subject: Add missing constraint. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/031b8be3bf03baa724dd7e225b0555726d089341?hp=9b913776e3da4d4879c001b9379808897273c8fd Add missing constraint. --- diff --git a/src/api/migrations/0006_alter_bookuserdata_unique_together.py b/src/api/migrations/0006_alter_bookuserdata_unique_together.py new file mode 100644 index 000000000..58d4b9a6b --- /dev/null +++ b/src/api/migrations/0006_alter_bookuserdata_unique_together.py @@ -0,0 +1,20 @@ +# Generated by Django 4.0.8 on 2023-05-23 09:10 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0043_alter_bookmedia_duration_alter_bookmedia_type'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('api', '0005_consumer_nonce_resource_token'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='bookuserdata', + unique_together={('user', 'book')}, + ), + ] diff --git a/src/api/models.py b/src/api/models.py index eb234ad8b..ffa4f9be2 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -50,6 +50,9 @@ class BookUserData(models.Model): complete = models.BooleanField(default=False) last_changed = models.DateTimeField(auto_now=True) + class Meta: + unique_together = [('user', 'book')] + @property def state(self): return 'complete' if self.complete else 'reading'