From 1fb74ba7e5c4107f88617d21bb214fb6a8baaa1f Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Mon, 18 Nov 2024 16:54:29 +0000 Subject: [PATCH] Add migration for GroupMembership model --- .../migrations/0001_initial.py | 25 +++++++++++++++++++ imperial_coldfront_plugin/models.py | 14 ++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 imperial_coldfront_plugin/migrations/0001_initial.py diff --git a/imperial_coldfront_plugin/migrations/0001_initial.py b/imperial_coldfront_plugin/migrations/0001_initial.py new file mode 100644 index 0000000..1c3198c --- /dev/null +++ b/imperial_coldfront_plugin/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.11 on 2024-11-18 16:50 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='GroupMembership', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_memberships_set', to=settings.AUTH_USER_MODEL)), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_group_memberships_set', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/imperial_coldfront_plugin/models.py b/imperial_coldfront_plugin/models.py index ae7aa91..deb78c6 100644 --- a/imperial_coldfront_plugin/models.py +++ b/imperial_coldfront_plugin/models.py @@ -4,7 +4,7 @@ from django.db import models -class GroupMember(models.Model): +class GroupMembership(models.Model): """Membership relationship within a group, associating an owner with a member. This model stores relationships where each instance represents an ownership @@ -19,5 +19,13 @@ class GroupMember(models.Model): AUTH_USER_MODEL. Deletes related memberships when the member is deleted. """ - owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - member = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + owner = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + related_name="owned_group_memberships_set", + ) + member = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + related_name="group_memberships_set", + )