From 031b8be3bf03baa724dd7e225b0555726d089341 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 23 May 2023 12:15:15 +0200 Subject: [PATCH 1/1] Add missing constraint. --- ...0006_alter_bookuserdata_unique_together.py | 20 +++++++++++++++++++ src/api/models.py | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 src/api/migrations/0006_alter_bookuserdata_unique_together.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 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' -- 2.20.1