diff --git a/api/funkwhale_api/favorites/migrations/0001_initial.py b/api/funkwhale_api/favorites/migrations/0001_initial.py index 0a6f0e5fc58e2dba299ccf0d645388f5b3e19056..c2bd03182d5c6791eda77c23fc593d38ef99e22a 100644 --- a/api/funkwhale_api/favorites/migrations/0001_initial.py +++ b/api/funkwhale_api/favorites/migrations/0001_initial.py @@ -19,8 +19,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), ('creation_date', models.DateTimeField(default=django.utils.timezone.now)), - ('track', models.ForeignKey(related_name='track_favorites', to='music.Track')), - ('user', models.ForeignKey(related_name='track_favorites', to=settings.AUTH_USER_MODEL)), + ('track', models.ForeignKey(related_name='track_favorites', to='music.Track', on_delete=models.CASCADE)), + ('user', models.ForeignKey(related_name='track_favorites', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)), ], options={ 'ordering': ('-creation_date',), diff --git a/api/funkwhale_api/favorites/models.py b/api/funkwhale_api/favorites/models.py index f9c6426e697471d9b520952e59a6409e7767266c..899ed9cff7f403bc2089e34cb3ff313ebaceff55 100644 --- a/api/funkwhale_api/favorites/models.py +++ b/api/funkwhale_api/favorites/models.py @@ -5,8 +5,10 @@ from funkwhale_api.music.models import Track class TrackFavorite(models.Model): creation_date = models.DateTimeField(default=timezone.now) - user = models.ForeignKey('users.User', related_name='track_favorites') - track = models.ForeignKey(Track, related_name='track_favorites') + user = models.ForeignKey( + 'users.User', related_name='track_favorites', on_delete=models.CASCADE) + track = models.ForeignKey( + Track, related_name='track_favorites', on_delete=models.CASCADE) class Meta: unique_together = ('track', 'user') diff --git a/api/funkwhale_api/history/migrations/0001_initial.py b/api/funkwhale_api/history/migrations/0001_initial.py index 5ddfc26f3b1ebf8bd46da81d76d319df7fda11e8..7b6f950edf38d474e5fa6488f2c42be8b3dbdb85 100644 --- a/api/funkwhale_api/history/migrations/0001_initial.py +++ b/api/funkwhale_api/history/migrations/0001_initial.py @@ -20,8 +20,8 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), ('end_date', models.DateTimeField(null=True, blank=True, default=django.utils.timezone.now)), ('session_key', models.CharField(null=True, blank=True, max_length=100)), - ('track', models.ForeignKey(related_name='listenings', to='music.Track')), - ('user', models.ForeignKey(blank=True, null=True, related_name='listenings', to=settings.AUTH_USER_MODEL)), + ('track', models.ForeignKey(related_name='listenings', to='music.Track', on_delete=models.CASCADE)), + ('user', models.ForeignKey(blank=True, null=True, related_name='listenings', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)), ], options={ 'ordering': ('-end_date',), diff --git a/api/funkwhale_api/history/models.py b/api/funkwhale_api/history/models.py index 0810ecf81d0bc7c82638958d6c26d73e4af3809c..f7f62de62a2f59a08edd9f0a9be28bed65c102fb 100644 --- a/api/funkwhale_api/history/models.py +++ b/api/funkwhale_api/history/models.py @@ -7,8 +7,14 @@ from funkwhale_api.music.models import Track class Listening(models.Model): end_date = models.DateTimeField(default=timezone.now, null=True, blank=True) - track = models.ForeignKey(Track, related_name="listenings") - user = models.ForeignKey('users.User', related_name="listenings", null=True, blank=True) + track = models.ForeignKey( + Track, related_name="listenings", on_delete=models.CASCADE) + user = models.ForeignKey( + 'users.User', + related_name="listenings", + null=True, + blank=True, + on_delete=models.CASCADE) session_key = models.CharField(max_length=100, null=True, blank=True) class Meta: diff --git a/api/funkwhale_api/music/migrations/0001_initial.py b/api/funkwhale_api/music/migrations/0001_initial.py index e78647948a3cb2062cbc7b2163f3872602b1bbea..265b81577f7ca52a4cb37e48f499b96cc4622d5b 100644 --- a/api/funkwhale_api/music/migrations/0001_initial.py +++ b/api/funkwhale_api/music/migrations/0001_initial.py @@ -44,7 +44,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')), ('creation_date', models.DateTimeField(default=django.utils.timezone.now)), - ('submitted_by', models.ForeignKey(related_name='imports', to=settings.AUTH_USER_MODEL)), + ('submitted_by', models.ForeignKey(related_name='imports', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)), ], ), migrations.CreateModel( @@ -54,7 +54,7 @@ class Migration(migrations.Migration): ('source', models.URLField()), ('mbid', models.UUIDField(editable=False)), ('status', models.CharField(default='pending', choices=[('pending', 'Pending'), ('finished', 'finished')], max_length=30)), - ('batch', models.ForeignKey(related_name='jobs', to='music.ImportBatch')), + ('batch', models.ForeignKey(related_name='jobs', to='music.ImportBatch', on_delete=models.CASCADE)), ], ), migrations.CreateModel( @@ -64,8 +64,8 @@ class Migration(migrations.Migration): ('mbid', models.UUIDField(editable=False, blank=True, null=True)), ('creation_date', models.DateTimeField(default=django.utils.timezone.now)), ('title', models.CharField(max_length=255)), - ('album', models.ForeignKey(related_name='tracks', blank=True, null=True, to='music.Album')), - ('artist', models.ForeignKey(related_name='tracks', to='music.Artist')), + ('album', models.ForeignKey(related_name='tracks', blank=True, null=True, to='music.Album', on_delete=models.CASCADE)), + ('artist', models.ForeignKey(related_name='tracks', to='music.Artist', on_delete=models.CASCADE)), ], options={ 'abstract': False, @@ -78,12 +78,12 @@ class Migration(migrations.Migration): ('audio_file', models.FileField(upload_to='tracks')), ('source', models.URLField(blank=True, null=True)), ('duration', models.IntegerField(blank=True, null=True)), - ('track', models.ForeignKey(related_name='files', to='music.Track')), + ('track', models.ForeignKey(related_name='files', to='music.Track', on_delete=models.CASCADE)), ], ), migrations.AddField( model_name='album', name='artist', - field=models.ForeignKey(related_name='albums', to='music.Artist'), + field=models.ForeignKey(related_name='albums', to='music.Artist', on_delete=models.CASCADE), ), ] diff --git a/api/funkwhale_api/music/migrations/0009_auto_20160920_1614.py b/api/funkwhale_api/music/migrations/0009_auto_20160920_1614.py index 2046a712765303f4044b627abed3813bf784a539..3a3d93989cdd436a6c9cbed010d1140e7bd933e1 100644 --- a/api/funkwhale_api/music/migrations/0009_auto_20160920_1614.py +++ b/api/funkwhale_api/music/migrations/0009_auto_20160920_1614.py @@ -39,11 +39,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='lyrics', name='work', - field=models.ForeignKey(related_name='lyrics', to='music.Work', blank=True, null=True), + field=models.ForeignKey(related_name='lyrics', to='music.Work', blank=True, null=True, on_delete=models.CASCADE), ), migrations.AddField( model_name='track', name='work', - field=models.ForeignKey(related_name='tracks', to='music.Work', blank=True, null=True), + field=models.ForeignKey(related_name='tracks', to='music.Work', blank=True, null=True, on_delete=models.CASCADE), ), ] diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index 95a47fd4a7ac6fabe2cd842d6ed2d9994e26b1bd..e5c87a601b8559b39b680308294bd1eb595274c8 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -108,7 +108,8 @@ def import_tracks(instance, cleaned_data, raw_data): class Album(APIModelMixin): title = models.CharField(max_length=255) - artist = models.ForeignKey(Artist, related_name='albums') + artist = models.ForeignKey( + Artist, related_name='albums', on_delete=models.CASCADE) release_date = models.DateField(null=True) release_group_id = models.UUIDField(null=True, blank=True) cover = VersatileImageField(upload_to='albums/covers/%Y/%m/%d', null=True, blank=True) @@ -245,7 +246,12 @@ class Work(APIModelMixin): class Lyrics(models.Model): - work = models.ForeignKey(Work, related_name='lyrics', null=True, blank=True) + work = models.ForeignKey( + Work, + related_name='lyrics', + null=True, + blank=True, + on_delete=models.CASCADE) url = models.URLField(unique=True) content = models.TextField(null=True, blank=True) @@ -268,10 +274,21 @@ class Lyrics(models.Model): class Track(APIModelMixin): title = models.CharField(max_length=255) - artist = models.ForeignKey(Artist, related_name='tracks') + artist = models.ForeignKey( + Artist, related_name='tracks', on_delete=models.CASCADE) position = models.PositiveIntegerField(null=True, blank=True) - album = models.ForeignKey(Album, related_name='tracks', null=True, blank=True) - work = models.ForeignKey(Work, related_name='tracks', null=True, blank=True) + album = models.ForeignKey( + Album, + related_name='tracks', + null=True, + blank=True, + on_delete=models.CASCADE) + work = models.ForeignKey( + Work, + related_name='tracks', + null=True, + blank=True, + on_delete=models.CASCADE) musicbrainz_model = 'recording' api = musicbrainz.api.recordings @@ -340,7 +357,8 @@ class Track(APIModelMixin): class TrackFile(models.Model): - track = models.ForeignKey(Track, related_name='files') + track = models.ForeignKey( + Track, related_name='files', on_delete=models.CASCADE) audio_file = models.FileField(upload_to='tracks/%Y/%m/%d', max_length=255) source = models.URLField(null=True, blank=True) duration = models.IntegerField(null=True, blank=True) @@ -376,7 +394,8 @@ class TrackFile(models.Model): class ImportBatch(models.Model): creation_date = models.DateTimeField(default=timezone.now) - submitted_by = models.ForeignKey('users.User', related_name='imports') + submitted_by = models.ForeignKey( + 'users.User', related_name='imports', on_delete=models.CASCADE) class Meta: ordering = ['-creation_date'] @@ -392,9 +411,14 @@ class ImportBatch(models.Model): return 'finished' class ImportJob(models.Model): - batch = models.ForeignKey(ImportBatch, related_name='jobs') + batch = models.ForeignKey( + ImportBatch, related_name='jobs', on_delete=models.CASCADE) track_file = models.ForeignKey( - TrackFile, related_name='jobs', null=True, blank=True) + TrackFile, + related_name='jobs', + null=True, + blank=True, + on_delete=models.CASCADE) source = models.URLField() mbid = models.UUIDField(editable=False) STATUS_CHOICES = ( diff --git a/api/funkwhale_api/playlists/migrations/0001_initial.py b/api/funkwhale_api/playlists/migrations/0001_initial.py index f42ca154e6064cb9de8f2f8dbb28c114e37dc5bd..bc97d81227ea49f8b46c0e0344fca6978a57b959 100644 --- a/api/funkwhale_api/playlists/migrations/0001_initial.py +++ b/api/funkwhale_api/playlists/migrations/0001_initial.py @@ -22,7 +22,7 @@ class Migration(migrations.Migration): ('name', models.CharField(max_length=50)), ('is_public', models.BooleanField(default=False)), ('creation_date', models.DateTimeField(default=django.utils.timezone.now)), - ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='playlists')), + ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='playlists', on_delete=models.CASCADE)), ], ), migrations.CreateModel( @@ -33,9 +33,9 @@ class Migration(migrations.Migration): ('rght', models.PositiveIntegerField(db_index=True, editable=False)), ('tree_id', models.PositiveIntegerField(db_index=True, editable=False)), ('position', models.PositiveIntegerField(db_index=True, editable=False)), - ('playlist', models.ForeignKey(to='playlists.Playlist', related_name='playlist_tracks')), - ('previous', mptt.fields.TreeOneToOneField(null=True, to='playlists.PlaylistTrack', related_name='next', blank=True)), - ('track', models.ForeignKey(to='music.Track', related_name='playlist_tracks')), + ('playlist', models.ForeignKey(to='playlists.Playlist', related_name='playlist_tracks', on_delete=models.CASCADE)), + ('previous', mptt.fields.TreeOneToOneField(null=True, to='playlists.PlaylistTrack', related_name='next', blank=True, on_delete=models.CASCADE)), + ('track', models.ForeignKey(to='music.Track', related_name='playlist_tracks', on_delete=models.CASCADE)), ], options={ 'ordering': ('-playlist', 'position'), diff --git a/api/funkwhale_api/playlists/models.py b/api/funkwhale_api/playlists/models.py index 35a30a704a06a494d0b37c322150cc6ee81cc660..e89dce81c93d23a4827e2b812e5894abcc948485 100644 --- a/api/funkwhale_api/playlists/models.py +++ b/api/funkwhale_api/playlists/models.py @@ -7,7 +7,8 @@ from mptt.models import MPTTModel, TreeOneToOneField class Playlist(models.Model): name = models.CharField(max_length=50) is_public = models.BooleanField(default=False) - user = models.ForeignKey('users.User', related_name="playlists") + user = models.ForeignKey( + 'users.User', related_name="playlists", on_delete=models.CASCADE) creation_date = models.DateTimeField(default=timezone.now) def __str__(self): @@ -21,9 +22,18 @@ class Playlist(models.Model): class PlaylistTrack(MPTTModel): - track = models.ForeignKey('music.Track', related_name='playlist_tracks') - previous = TreeOneToOneField('self', blank=True, null=True, related_name='next') - playlist = models.ForeignKey(Playlist, related_name='playlist_tracks') + track = models.ForeignKey( + 'music.Track', + related_name='playlist_tracks', + on_delete=models.CASCADE) + previous = TreeOneToOneField( + 'self', + blank=True, + null=True, + related_name='next', + on_delete=models.CASCADE) + playlist = models.ForeignKey( + Playlist, related_name='playlist_tracks', on_delete=models.CASCADE) class MPTTMeta: level_attr = 'position' diff --git a/api/funkwhale_api/radios/migrations/0001_initial.py b/api/funkwhale_api/radios/migrations/0001_initial.py index 9ec25805db927845610d9f3f071e574b8d450904..46faf749edaf0d0baa5e98ce320ad4636b8426a4 100644 --- a/api/funkwhale_api/radios/migrations/0001_initial.py +++ b/api/funkwhale_api/radios/migrations/0001_initial.py @@ -20,7 +20,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), ('radio_type', models.CharField(max_length=50)), ('creation_date', models.DateTimeField(default=django.utils.timezone.now)), - ('user', models.ForeignKey(related_name='radio_sessions', blank=True, to=settings.AUTH_USER_MODEL, null=True)), + ('user', models.ForeignKey(related_name='radio_sessions', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)), ], ), migrations.CreateModel( @@ -28,8 +28,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), ('position', models.IntegerField(default=1)), - ('session', models.ForeignKey(to='radios.RadioSession', related_name='session_tracks')), - ('track', models.ForeignKey(to='music.Track', related_name='radio_session_tracks')), + ('session', models.ForeignKey(to='radios.RadioSession', related_name='session_tracks', on_delete=models.CASCADE)), + ('track', models.ForeignKey(to='music.Track', related_name='radio_session_tracks', on_delete=models.CASCADE)), ], options={ 'ordering': ('session', 'position'), diff --git a/api/funkwhale_api/radios/migrations/0003_auto_20160521_1708.py b/api/funkwhale_api/radios/migrations/0003_auto_20160521_1708.py index 4629d68fefb121b0ed5e2f975cd7c1e08b53e3b3..7c70abc2e12ed6309de4bf274ff94a26b2ba20e6 100644 --- a/api/funkwhale_api/radios/migrations/0003_auto_20160521_1708.py +++ b/api/funkwhale_api/radios/migrations/0003_auto_20160521_1708.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='radiosession', name='related_object_content_type', - field=models.ForeignKey(null=True, to='contenttypes.ContentType', blank=True), + field=models.ForeignKey(null=True, to='contenttypes.ContentType', blank=True, on_delete=models.CASCADE), ), migrations.AddField( model_name='radiosession', diff --git a/api/funkwhale_api/radios/models.py b/api/funkwhale_api/radios/models.py index a3a3531328a0565bd3c287377c40b855a8f1ec64..984b34a1f7d86230c6e9186c123246286f0c6eac 100644 --- a/api/funkwhale_api/radios/models.py +++ b/api/funkwhale_api/radios/models.py @@ -7,11 +7,20 @@ from django.contrib.contenttypes.models import ContentType from funkwhale_api.music.models import Track class RadioSession(models.Model): - user = models.ForeignKey('users.User', related_name='radio_sessions', null=True, blank=True) + user = models.ForeignKey( + 'users.User', + related_name='radio_sessions', + null=True, + blank=True, + on_delete=models.CASCADE) session_key = models.CharField(max_length=100, null=True, blank=True) radio_type = models.CharField(max_length=50) creation_date = models.DateTimeField(default=timezone.now) - related_object_content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True) + related_object_content_type = models.ForeignKey( + ContentType, + blank=True, + null=True, + on_delete=models.CASCADE) related_object_id = models.PositiveIntegerField(blank=True, null=True) related_object = GenericForeignKey('related_object_content_type', 'related_object_id') @@ -43,9 +52,11 @@ class RadioSession(models.Model): return registry[self.radio_type](session=self) class RadioSessionTrack(models.Model): - session = models.ForeignKey(RadioSession, related_name='session_tracks') + session = models.ForeignKey( + RadioSession, related_name='session_tracks', on_delete=models.CASCADE) position = models.IntegerField(default=1) - track = models.ForeignKey(Track, related_name='radio_session_tracks') + track = models.ForeignKey( + Track, related_name='radio_session_tracks', on_delete=models.CASCADE) class Meta: ordering = ('session', 'position')