From 982f08cd7b7618dfee76af6aa16c7da711bd7f57 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Sun, 15 Oct 2023 01:27:56 +0300 Subject: [PATCH] Only one subscription per user --- .../0015_alter_subscription_user.py | 25 +++++++++++++++++++ subscription/models.py | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 subscription/migrations/0015_alter_subscription_user.py diff --git a/subscription/migrations/0015_alter_subscription_user.py b/subscription/migrations/0015_alter_subscription_user.py new file mode 100644 index 000000000..30baa3d6b --- /dev/null +++ b/subscription/migrations/0015_alter_subscription_user.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.5 on 2023-10-14 22:27 + +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), + ("subscription", "0014_alter_subscriptionindexpage_body"), + ] + + operations = [ + migrations.AlterField( + model_name="subscription", + name="user", + field=models.OneToOneField( + on_delete=django.db.models.deletion.PROTECT, + related_name="subscription", + to=settings.AUTH_USER_MODEL, + verbose_name="subscriber", + ), + ), + ] diff --git a/subscription/models.py b/subscription/models.py index 4bdddfd96..edb13c3a4 100644 --- a/subscription/models.py +++ b/subscription/models.py @@ -21,12 +21,12 @@ class Subscription(models.Model): """A subscription to the magazine.""" - user = models.ForeignKey( + user = models.OneToOneField( settings.AUTH_USER_MODEL, verbose_name="subscriber", editable=True, on_delete=models.PROTECT, - related_name="subscriptions", + related_name="subscription", unique=True, # Only one subscription per user )