diff --git a/frontend/migrations/0008_accountlog_unique_account_log_for_each_type.py b/frontend/migrations/0008_accountlog_unique_account_log_for_each_type.py new file mode 100644 index 0000000..5f9f20b --- /dev/null +++ b/frontend/migrations/0008_accountlog_unique_account_log_for_each_type.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.5 on 2023-10-12 18:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("frontend", "0007_accountlog_specialprofileusedrecord_and_more"), + ] + + operations = [ + migrations.AddConstraint( + model_name="accountlog", + constraint=models.UniqueConstraint( + fields=("account", "content_type"), + name="unique_account_log_for_each_type", + ), + ), + ] diff --git a/frontend/models.py b/frontend/models.py index 7ba5a93..9ddc56e 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -79,6 +79,12 @@ class AccountLog(models.Model): def __str__(self): return f"Account {self.account.pk} ({self.content_type} {self.contents})" + + class Meta: + constraints = [ + models.UniqueConstraint(fields=['account', 'content_type'], + name='unique_account_log_for_each_type'), + ] # 记录需要在首次登录后显示换组页面并且已经换组的用户