From 1e83a91b5e5f5586f0c681cb94425452990d041e Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 22 Jun 2022 13:05:43 +0200 Subject: [PATCH] chore(api): use named argument for on_delete --- api/libretime_api/core/models/auth.py | 7 +++-- api/libretime_api/core/models/worker.py | 10 +++++-- api/libretime_api/history/models/listener.py | 4 +-- api/libretime_api/history/models/played.py | 19 +++++++++--- api/libretime_api/podcasts/models/podcast.py | 18 ++++++++---- api/libretime_api/schedule/models/playlist.py | 28 +++++++++++++++--- api/libretime_api/schedule/models/schedule.py | 16 ++++++++-- api/libretime_api/schedule/models/show.py | 29 ++++++++++++++----- .../schedule/models/smart_block.py | 23 ++++++++++++--- .../schedule/models/webstream.py | 2 +- .../storage/models/cloud_file.py | 6 +++- api/libretime_api/storage/models/file.py | 11 +++++-- 12 files changed, 134 insertions(+), 39 deletions(-) diff --git a/api/libretime_api/core/models/auth.py b/api/libretime_api/core/models/auth.py index d7faedeb9..533ad21bc 100644 --- a/api/libretime_api/core/models/auth.py +++ b/api/libretime_api/core/models/auth.py @@ -2,7 +2,7 @@ from django.db import models class UserToken(models.Model): - user = models.ForeignKey("User", models.DO_NOTHING) + user = models.ForeignKey("User", on_delete=models.DO_NOTHING) action = models.CharField(max_length=255) token = models.CharField(unique=True, max_length=40) created = models.DateTimeField() @@ -18,7 +18,10 @@ class UserToken(models.Model): class Session(models.Model): sessid = models.CharField(primary_key=True, max_length=32) userid = models.ForeignKey( - "User", models.DO_NOTHING, db_column="userid", blank=True, null=True + "User", + on_delete=models.DO_NOTHING, + blank=True, + null=True, ) login = models.CharField(max_length=255, blank=True, null=True) ts = models.DateTimeField(blank=True, null=True) diff --git a/api/libretime_api/core/models/worker.py b/api/libretime_api/core/models/worker.py index 4fcde6cfb..a5a314bc8 100644 --- a/api/libretime_api/core/models/worker.py +++ b/api/libretime_api/core/models/worker.py @@ -4,7 +4,12 @@ from django.db import models class ThirdPartyTrackReference(models.Model): service = models.CharField(max_length=256) foreign_id = models.CharField(unique=True, max_length=256, blank=True, null=True) - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) upload_time = models.DateTimeField(blank=True, null=True) status = models.CharField(max_length=256, blank=True, null=True) @@ -16,7 +21,8 @@ class ThirdPartyTrackReference(models.Model): class CeleryTask(models.Model): task_id = models.CharField(max_length=256) track_reference = models.ForeignKey( - "ThirdPartyTrackReference", models.DO_NOTHING, db_column="track_reference" + "ThirdPartyTrackReference", + on_delete=models.DO_NOTHING, ) name = models.CharField(max_length=256, blank=True, null=True) dispatch_time = models.DateTimeField(blank=True, null=True) diff --git a/api/libretime_api/history/models/listener.py b/api/libretime_api/history/models/listener.py index 038ff56e2..f22128565 100644 --- a/api/libretime_api/history/models/listener.py +++ b/api/libretime_api/history/models/listener.py @@ -18,8 +18,8 @@ class Timestamp(models.Model): class ListenerCount(models.Model): - timestamp = models.ForeignKey("Timestamp", models.DO_NOTHING) - mount_name = models.ForeignKey("MountName", models.DO_NOTHING) + timestamp = models.ForeignKey("Timestamp", on_delete=models.DO_NOTHING) + mount_name = models.ForeignKey("MountName", on_delete=models.DO_NOTHING) listener_count = models.IntegerField() class Meta: diff --git a/api/libretime_api/history/models/played.py b/api/libretime_api/history/models/played.py index 2263dec49..ba7635491 100644 --- a/api/libretime_api/history/models/played.py +++ b/api/libretime_api/history/models/played.py @@ -2,11 +2,19 @@ from django.db import models class PlayoutHistory(models.Model): - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) starts = models.DateTimeField() ends = models.DateTimeField(blank=True, null=True) instance = models.ForeignKey( - "schedule.ShowInstance", models.DO_NOTHING, blank=True, null=True + "schedule.ShowInstance", + on_delete=models.DO_NOTHING, + blank=True, + null=True, ) class Meta: @@ -15,7 +23,10 @@ class PlayoutHistory(models.Model): class PlayoutHistoryMetadata(models.Model): - history = models.ForeignKey("PlayoutHistory", models.DO_NOTHING) + history = models.ForeignKey( + "PlayoutHistory", + on_delete=models.DO_NOTHING, + ) key = models.CharField(max_length=128) value = models.CharField(max_length=128) @@ -34,7 +45,7 @@ class PlayoutHistoryTemplate(models.Model): class PlayoutHistoryTemplateField(models.Model): - template = models.ForeignKey("PlayoutHistoryTemplate", models.DO_NOTHING) + template = models.ForeignKey("PlayoutHistoryTemplate", on_delete=models.DO_NOTHING) name = models.CharField(max_length=128) label = models.CharField(max_length=128) type = models.CharField(max_length=128) diff --git a/api/libretime_api/podcasts/models/podcast.py b/api/libretime_api/podcasts/models/podcast.py index 95d9ffacc..e136307bd 100644 --- a/api/libretime_api/podcasts/models/podcast.py +++ b/api/libretime_api/podcasts/models/podcast.py @@ -16,7 +16,10 @@ class Podcast(models.Model): itunes_category = models.CharField(max_length=4096, blank=True, null=True) itunes_explicit = models.CharField(max_length=4096, blank=True, null=True) owner = models.ForeignKey( - "core.User", models.DO_NOTHING, db_column="owner", blank=True, null=True + "core.User", + on_delete=models.DO_NOTHING, + blank=True, + null=True, ) def get_owner(self): @@ -32,8 +35,13 @@ class Podcast(models.Model): class PodcastEpisode(models.Model): - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) - podcast = models.ForeignKey("Podcast", models.DO_NOTHING) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + podcast = models.ForeignKey("Podcast", on_delete=models.DO_NOTHING) publication_date = models.DateTimeField() download_url = models.CharField(max_length=4096) episode_guid = models.CharField(max_length=4096) @@ -59,7 +67,7 @@ class PodcastEpisode(models.Model): class StationPodcast(models.Model): - podcast = models.ForeignKey("Podcast", models.DO_NOTHING) + podcast = models.ForeignKey("Podcast", on_delete=models.DO_NOTHING) def get_owner(self): return self.podcast.owner @@ -73,7 +81,7 @@ class ImportedPodcast(models.Model): auto_ingest = models.BooleanField() auto_ingest_timestamp = models.DateTimeField(blank=True, null=True) album_override = models.BooleanField() - podcast = models.ForeignKey("Podcast", models.DO_NOTHING) + podcast = models.ForeignKey("Podcast", on_delete=models.DO_NOTHING) def get_owner(self): return self.podcast.owner diff --git a/api/libretime_api/schedule/models/playlist.py b/api/libretime_api/schedule/models/playlist.py index 1454f2587..5b2fc8154 100644 --- a/api/libretime_api/schedule/models/playlist.py +++ b/api/libretime_api/schedule/models/playlist.py @@ -5,7 +5,12 @@ class Playlist(models.Model): name = models.CharField(max_length=255) mtime = models.DateTimeField(blank=True, null=True) utime = models.DateTimeField(blank=True, null=True) - creator = models.ForeignKey("core.User", models.DO_NOTHING, blank=True, null=True) + creator = models.ForeignKey( + "core.User", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) description = models.CharField(max_length=512, blank=True, null=True) length = models.DurationField(blank=True, null=True) @@ -18,9 +23,24 @@ class Playlist(models.Model): class PlaylistContent(models.Model): - playlist = models.ForeignKey("Playlist", models.DO_NOTHING, blank=True, null=True) - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) - block = models.ForeignKey("SmartBlock", models.DO_NOTHING, blank=True, null=True) + playlist = models.ForeignKey( + "Playlist", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + block = models.ForeignKey( + "SmartBlock", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) stream_id = models.IntegerField(blank=True, null=True) type = models.SmallIntegerField() position = models.IntegerField(blank=True, null=True) diff --git a/api/libretime_api/schedule/models/schedule.py b/api/libretime_api/schedule/models/schedule.py index 4dc8b823f..d226d70bc 100644 --- a/api/libretime_api/schedule/models/schedule.py +++ b/api/libretime_api/schedule/models/schedule.py @@ -4,15 +4,25 @@ from django.db import models class Schedule(models.Model): starts = models.DateTimeField() ends = models.DateTimeField() - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) - stream = models.ForeignKey("Webstream", models.DO_NOTHING, blank=True, null=True) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + stream = models.ForeignKey( + "Webstream", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) clip_length = models.DurationField(blank=True, null=True) fade_in = models.TimeField(blank=True, null=True) fade_out = models.TimeField(blank=True, null=True) cue_in = models.DurationField() cue_out = models.DurationField() media_item_played = models.BooleanField(blank=True, null=True) - instance = models.ForeignKey("ShowInstance", models.DO_NOTHING) + instance = models.ForeignKey("ShowInstance", on_delete=models.DO_NOTHING) playout_status = models.SmallIntegerField() broadcasted = models.SmallIntegerField() position = models.IntegerField() diff --git a/api/libretime_api/schedule/models/show.py b/api/libretime_api/schedule/models/show.py index 33674d24b..39af85cd0 100644 --- a/api/libretime_api/schedule/models/show.py +++ b/api/libretime_api/schedule/models/show.py @@ -17,7 +17,10 @@ class Show(models.Model): image_path = models.CharField(max_length=255, blank=True, null=True) has_autoplaylist = models.BooleanField() autoplaylist = models.ForeignKey( - "Playlist", models.DO_NOTHING, blank=True, null=True + "Playlist", + on_delete=models.DO_NOTHING, + blank=True, + null=True, ) autoplaylist_repeat = models.BooleanField() @@ -38,7 +41,7 @@ class ShowDays(models.Model): day = models.SmallIntegerField(blank=True, null=True) repeat_type = models.SmallIntegerField() next_pop_date = models.DateField(blank=True, null=True) - show = models.ForeignKey("Show", models.DO_NOTHING) + show = models.ForeignKey("Show", on_delete=models.DO_NOTHING) record = models.SmallIntegerField(blank=True, null=True) def get_owner(self): @@ -50,8 +53,8 @@ class ShowDays(models.Model): class ShowHost(models.Model): - show = models.ForeignKey("Show", models.DO_NOTHING) - subjs = models.ForeignKey("core.User", models.DO_NOTHING) + show = models.ForeignKey("Show", on_delete=models.DO_NOTHING) + subjs = models.ForeignKey("core.User", on_delete=models.DO_NOTHING) class Meta: managed = False @@ -62,11 +65,21 @@ class ShowInstance(models.Model): description = models.CharField(max_length=8192, blank=True, null=True) starts = models.DateTimeField() ends = models.DateTimeField() - show = models.ForeignKey("Show", models.DO_NOTHING) + show = models.ForeignKey("Show", on_delete=models.DO_NOTHING) record = models.SmallIntegerField(blank=True, null=True) rebroadcast = models.SmallIntegerField(blank=True, null=True) - instance = models.ForeignKey("self", models.DO_NOTHING, blank=True, null=True) - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) + instance = models.ForeignKey( + "self", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) time_filled = models.DurationField(blank=True, null=True) created = models.DateTimeField() last_scheduled = models.DateTimeField(blank=True, null=True) @@ -84,7 +97,7 @@ class ShowInstance(models.Model): class ShowRebroadcast(models.Model): day_offset = models.CharField(max_length=1024) start_time = models.TimeField() - show = models.ForeignKey("Show", models.DO_NOTHING) + show = models.ForeignKey("Show", on_delete=models.DO_NOTHING) def get_owner(self): return self.show.get_owner() diff --git a/api/libretime_api/schedule/models/smart_block.py b/api/libretime_api/schedule/models/smart_block.py index f34b49154..73c3244e0 100644 --- a/api/libretime_api/schedule/models/smart_block.py +++ b/api/libretime_api/schedule/models/smart_block.py @@ -5,7 +5,12 @@ class SmartBlock(models.Model): name = models.CharField(max_length=255) mtime = models.DateTimeField(blank=True, null=True) utime = models.DateTimeField(blank=True, null=True) - creator = models.ForeignKey("core.User", models.DO_NOTHING, blank=True, null=True) + creator = models.ForeignKey( + "core.User", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) description = models.CharField(max_length=512, blank=True, null=True) length = models.DurationField(blank=True, null=True) type = models.CharField(max_length=7, blank=True, null=True) @@ -29,8 +34,18 @@ class SmartBlock(models.Model): class SmartBlockContent(models.Model): - block = models.ForeignKey("SmartBlock", models.DO_NOTHING, blank=True, null=True) - file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True) + block = models.ForeignKey( + "SmartBlock", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) + file = models.ForeignKey( + "storage.File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) position = models.IntegerField(blank=True, null=True) trackoffset = models.FloatField() cliplength = models.DurationField(blank=True, null=True) @@ -63,7 +78,7 @@ class SmartBlockCriteria(models.Model): value = models.CharField(max_length=512) extra = models.CharField(max_length=512, blank=True, null=True) criteriagroup = models.IntegerField(blank=True, null=True) - block = models.ForeignKey("SmartBlock", models.DO_NOTHING) + block = models.ForeignKey("SmartBlock", on_delete=models.DO_NOTHING) def get_owner(self): return self.block.get_owner() diff --git a/api/libretime_api/schedule/models/webstream.py b/api/libretime_api/schedule/models/webstream.py index f3f9a6487..5f9a6c89b 100644 --- a/api/libretime_api/schedule/models/webstream.py +++ b/api/libretime_api/schedule/models/webstream.py @@ -26,7 +26,7 @@ class Webstream(models.Model): class WebstreamMetadata(models.Model): - instance = models.ForeignKey("Schedule", models.DO_NOTHING) + instance = models.ForeignKey("Schedule", on_delete=models.DO_NOTHING) start_time = models.DateTimeField() liquidsoap_data = models.CharField(max_length=1024) diff --git a/api/libretime_api/storage/models/cloud_file.py b/api/libretime_api/storage/models/cloud_file.py index 084cb468b..915fe100b 100644 --- a/api/libretime_api/storage/models/cloud_file.py +++ b/api/libretime_api/storage/models/cloud_file.py @@ -5,7 +5,11 @@ class CloudFile(models.Model): storage_backend = models.CharField(max_length=512) resource_id = models.TextField() filename = models.ForeignKey( - "File", models.DO_NOTHING, blank=True, null=True, db_column="cc_file_id" + "File", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + db_column="cc_file_id", ) class Meta: diff --git a/api/libretime_api/storage/models/file.py b/api/libretime_api/storage/models/file.py index ac2e6cc0e..c9679edb2 100644 --- a/api/libretime_api/storage/models/file.py +++ b/api/libretime_api/storage/models/file.py @@ -10,11 +10,11 @@ class File(models.Model): currently_accessing = models.IntegerField(db_column="currentlyaccessing") edited_by = models.ForeignKey( "core.User", - models.DO_NOTHING, - db_column="editedby", + on_delete=models.DO_NOTHING, blank=True, null=True, related_name="edited_files", + db_column="editedby", ) mtime = models.DateTimeField(blank=True, null=True) utime = models.DateTimeField(blank=True, null=True) @@ -67,7 +67,12 @@ class File(models.Model): replay_gain = models.DecimalField( max_digits=8, decimal_places=2, blank=True, null=True ) - owner = models.ForeignKey("core.User", models.DO_NOTHING, blank=True, null=True) + owner = models.ForeignKey( + "core.User", + on_delete=models.DO_NOTHING, + blank=True, + null=True, + ) cuein = models.DurationField(blank=True, null=True) cueout = models.DurationField(blank=True, null=True) silan_check = models.BooleanField(blank=True, null=True)