From 34aa91ad9e886b2f566903e9943c4b28d5e3c419 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 10 May 2024 13:37:17 -0500 Subject: [PATCH] add unique constraint on name + hostmask I'm thinking that the command to log out will be LOGOUT , which means the user hostmask must have an unambiguous link to name Signed-off-by: Brian S. Stephan --- ...r_player_must_have_unique_character_names.py | 17 +++++++++++++++++ idlerpg/models.py | 1 + 2 files changed, 18 insertions(+) create mode 100644 idlerpg/migrations/0002_character_player_must_have_unique_character_names.py diff --git a/idlerpg/migrations/0002_character_player_must_have_unique_character_names.py b/idlerpg/migrations/0002_character_player_must_have_unique_character_names.py new file mode 100644 index 0000000..99c227e --- /dev/null +++ b/idlerpg/migrations/0002_character_player_must_have_unique_character_names.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.5 on 2024-05-10 18:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('idlerpg', '0001_initial'), + ] + + operations = [ + migrations.AddConstraint( + model_name='character', + constraint=models.UniqueConstraint(models.F('name'), models.F('hostmask'), name='player_must_have_unique_character_names'), + ), + ] diff --git a/idlerpg/models.py b/idlerpg/models.py index b4bad4c..1f09fcc 100644 --- a/idlerpg/models.py +++ b/idlerpg/models.py @@ -121,6 +121,7 @@ class Character(models.Model): constraints = [ models.UniqueConstraint("game", "hostmask", name="one_player_character_per_game"), models.UniqueConstraint("game", "name", name="no_characters_with_same_name_per_game"), + models.UniqueConstraint("name", "hostmask", name="player_must_have_unique_character_names"), ] def __str__(self):