Skip to content

Commit

Permalink
fix!(models): modify on_delete behaviour for instrument, avresource, …
Browse files Browse the repository at this point in the history
…instrumentname models

- On the Instrument model, set default_image and thumbnail to NULL if related
AVResource object is deleted.
- On the InstrumentName model, delete the InstrumentName if the related Instrument
is deleted.
- On the AVResource model, set the instrument field to NULL if the related Instrument
is deleted.
  • Loading branch information
dchiller committed Aug 14, 2024
1 parent b145416 commit 62feb7d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.5 on 2024-08-14 22:18

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('instruments', '0002_instrument_thumbnail'),
]

operations = [
migrations.AlterField(
model_name='avresource',
name='instrument',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='instruments.instrument'),
),
migrations.AlterField(
model_name='instrument',
name='default_image',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_image_of', to='instruments.avresource'),
),
migrations.AlterField(
model_name='instrument',
name='thumbnail',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='thumbnail_of', to='instruments.avresource'),
),
migrations.AlterField(
model_name='instrumentname',
name='instrument',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='instruments.instrument'),
),
]
2 changes: 1 addition & 1 deletion web-app/django/VIM/apps/instruments/models/avresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AVResource(models.Model):
("image", "Image"),
]

instrument = models.ForeignKey("Instrument", on_delete=models.PROTECT)
instrument = models.ForeignKey("Instrument", on_delete=models.SET_NULL, null=True)
type = models.CharField(
max_length=5,
choices=RESOURCE_TYPE_CHOICES,
Expand Down
4 changes: 2 additions & 2 deletions web-app/django/VIM/apps/instruments/models/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class Instrument(models.Model):
wikidata_id = models.CharField(max_length=20, unique=True)
default_image = models.ForeignKey(
"AVResource",
on_delete=models.PROTECT,
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="default_image_of",
)
thumbnail = models.ForeignKey(
"AVResource",
on_delete=models.PROTECT,
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="thumbnail_of",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class InstrumentName(models.Model):
instrument = models.ForeignKey("Instrument", on_delete=models.PROTECT)
instrument = models.ForeignKey("Instrument", on_delete=models.CASCADE)
language = models.ForeignKey("Language", on_delete=models.PROTECT)
name = models.CharField(max_length=50, blank=False)
source_name = models.CharField(
Expand Down

0 comments on commit 62feb7d

Please sign in to comment.