From fc7d53abe77f11657fb57f6a6cbf1953d8f5d9ec Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 7 Jun 2021 10:48:41 +0900 Subject: [PATCH] Add ExampleState model --- backend/api/migrations/0015_examplestate.py | 28 +++++++++++++++++++++ backend/api/models.py | 16 ++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 backend/api/migrations/0015_examplestate.py diff --git a/backend/api/migrations/0015_examplestate.py b/backend/api/migrations/0015_examplestate.py new file mode 100644 index 00000000..77c916e6 --- /dev/null +++ b/backend/api/migrations/0015_examplestate.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.3 on 2021-06-07 01:48 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('api', '0014_auto_20210603_0438'), + ] + + operations = [ + migrations.CreateModel( + name='ExampleState', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('confirmed_at', models.DateTimeField(auto_now=True)), + ('confirmed_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('example', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='states', to='api.example')), + ], + options={ + 'unique_together': {('example', 'confirmed_by')}, + }, + ), + ] diff --git a/backend/api/models.py b/backend/api/models.py index 9e7b8152..feda70cc 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -149,6 +149,22 @@ class Example(models.Model): return Comment.objects.filter(example=self.id).count() +class ExampleState(models.Model): + example = models.ForeignKey( + to=Example, + on_delete=models.CASCADE, + related_name='states' + ) + confirmed_by = models.ForeignKey( + to=User, + on_delete=models.CASCADE + ) + confirmed_at = models.DateTimeField(auto_now=True) + + class Meta: + unique_together = (('example', 'confirmed_by'),) + + class Comment(models.Model): text = models.TextField() example = models.ForeignKey(