Skip to content

Commit

Permalink
Only one subscription per user
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Oct 14, 2023
1 parent cc33cec commit 982f08c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions subscription/migrations/0015_alter_subscription_user.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
4 changes: 2 additions & 2 deletions subscription/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 982f08c

Please sign in to comment.