Fixed unique constraint issue for subchannel model
Subchannel unique constraint now applies to a matching pair of channel_id and subscription, oppose to the previous constraint; unique subscription only.
This commit is contained in:
parent
71e6e5c603
commit
43664f57df
@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.0.1 on 2024-04-28 14:50
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0004_remove_subchannel_subscription_id_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='subchannel',
|
||||
options={'get_latest_by': 'id', 'verbose_name': 'SubChannel', 'verbose_name_plural': 'SubChannels'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subchannel',
|
||||
name='subscription',
|
||||
field=models.ForeignKey(help_text='The linked Subscription, must be unique.', on_delete=django.db.models.deletion.CASCADE, to='home.subscription'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='subchannel',
|
||||
constraint=models.UniqueConstraint(fields=('channel_id', 'subscription'), name='unique channel id and subscription pair'),
|
||||
),
|
||||
]
|
@ -125,10 +125,24 @@ class SubChannel(models.Model):
|
||||
subscription = models.ForeignKey(
|
||||
to="home.Subscription",
|
||||
on_delete=models.CASCADE,
|
||||
unique=True,
|
||||
help_text=_("The linked Subscription, must be unique.")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Metadata for the SubChannel Model.
|
||||
"""
|
||||
|
||||
verbose_name = "SubChannel"
|
||||
verbose_name_plural = "SubChannels"
|
||||
get_latest_by = "id"
|
||||
constraints = [
|
||||
# Prevent servers from having subscriptions with duplicate names
|
||||
models.UniqueConstraint(
|
||||
fields=["channel_id", "subscription"],
|
||||
name="unique channel id and subscription pair")
|
||||
]
|
||||
|
||||
|
||||
class Subscription(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user