Add missing constraint.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 10:15:15 +0000 (12:15 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 10:15:15 +0000 (12:15 +0200)
src/api/migrations/0006_alter_bookuserdata_unique_together.py [new file with mode: 0644]
src/api/models.py

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 (file)
index 0000000..58d4b9a
--- /dev/null
@@ -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')},
+        ),
+    ]
index eb234ad..ffa4f9b 100644 (file)
@@ -50,6 +50,9 @@ class BookUserData(models.Model):
     complete = models.BooleanField(default=False)
     last_changed = models.DateTimeField(auto_now=True)
 
     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'
     @property
     def state(self):
         return 'complete' if self.complete else 'reading'