-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛(back) change thumbnail video relation to ForeignKey field
The relation between thumbnail and video was a OneToOneField and it is exactly the behavior we want. Unfortunately the app djang-safedelete does not manage it and it is then impossible for us to delete a thumbnail belonging to a video. The thumbnail is always return. To fix this issue we decided to change the relation with a ForeignKey field and to mimic the behavior of a OneToOneField by adding a UniqueConstraint and managing the uniqueness of the resource in the VideoSerializer. Moreover, we must keep the thumbnail instance in the VideoSerializer to avoid to query the database again and again to fetch the instance every time we need it. Without this, the number of queries is growing. An issue is open to track this bug makinacorpus/django-safedelete#211
- Loading branch information
Showing
6 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/backend/marsha/core/migrations/0048_modify_thumbnail_video_relation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 4.0.5 on 2022-06-07 13:00 | ||
|
||
from django.conf import settings | ||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0047_add_video_join_mode"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="thumbnail", | ||
name="video", | ||
field=models.ForeignKey( | ||
help_text="video for which this thumbnail is", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="thumbnail", | ||
to="core.video", | ||
verbose_name="video", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="thumbnail", | ||
constraint=models.UniqueConstraint( | ||
condition=models.Q(("deleted", None)), | ||
fields=("video",), | ||
name="thumbnail_video_unique_idx", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters