diff --git a/apps/api/serializers.py b/apps/api/serializers.py index 35d87c1..9f682f1 100644 --- a/apps/api/serializers.py +++ b/apps/api/serializers.py @@ -158,8 +158,10 @@ class MessageStyleSerializer(DynamicModelSerializer): "show_images", "fetch_images", "title_mutator", - "description_mutator" + "description_mutator", + "auto_created" ) + read_only_fields = ("auto_created",) class UniqueContentRuleSerializer(DynamicModelSerializer): diff --git a/apps/home/admin.py b/apps/home/admin.py index 031729c..2558c40 100644 --- a/apps/home/admin.py +++ b/apps/home/admin.py @@ -7,6 +7,7 @@ from .models import ( ContentFilter, MessageMutator, MessageStyle, + DiscordChannel, Subscription, Content, UniqueContentRule @@ -52,7 +53,16 @@ class MessageStyleAdmin(admin.ModelAdmin): "show_images", "fetch_images", "title_mutator", - "description_mutator" + "description_mutator", + "auto_created" + ] + + +@admin.register(DiscordChannel) +class DiscordChannelAdmin(admin.ModelAdmin): + list_display = [ + "id", + "channel_id" ] diff --git a/apps/home/migrations/0005_discordchannel_subscription_channels.py b/apps/home/migrations/0005_discordchannel_subscription_channels.py new file mode 100644 index 0000000..40f5c54 --- /dev/null +++ b/apps/home/migrations/0005_discordchannel_subscription_channels.py @@ -0,0 +1,26 @@ +# Generated by Django 5.0.4 on 2024-10-01 12:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0004_messagestyle_name'), + ] + + operations = [ + migrations.CreateModel( + name='DiscordChannel', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('channel_id', models.BigIntegerField()), + ('name', models.CharField(max_length=128)), + ], + ), + migrations.AddField( + model_name='subscription', + name='channels', + field=models.ManyToManyField(blank=True, related_name='subscriptions', to='home.discordchannel'), + ), + ] diff --git a/apps/home/migrations/0006_remove_discordchannel_name_messagestyle_auto_created.py b/apps/home/migrations/0006_remove_discordchannel_name_messagestyle_auto_created.py new file mode 100644 index 0000000..8122c14 --- /dev/null +++ b/apps/home/migrations/0006_remove_discordchannel_name_messagestyle_auto_created.py @@ -0,0 +1,22 @@ +# Generated by Django 5.0.4 on 2024-10-01 20:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0005_discordchannel_subscription_channels'), + ] + + operations = [ + migrations.RemoveField( + model_name='discordchannel', + name='name', + ), + migrations.AddField( + model_name='messagestyle', + name='auto_created', + field=models.BooleanField(blank=True, default=False), + ), + ] diff --git a/apps/home/models.py b/apps/home/models.py index 1b3fed9..c76b930 100644 --- a/apps/home/models.py +++ b/apps/home/models.py @@ -138,13 +138,15 @@ class MessageStyle(models.Model): blank=True ) + auto_created = models.BooleanField(default=False, blank=True) + class Meta: verbose_name = "message style" verbose_name_plural = "message styles" get_latest_by = "id" def __str__(self): - return f"{self.server.name} - {self.id}" + return self.name @receiver(post_save, sender=Server) @@ -165,7 +167,8 @@ def create_default_items(sender, instance, created, **kwargs): show_images=True, fetch_images=True, title_mutator=None, - description_mutator=None + description_mutator=None, + auto_created=True ) @@ -191,6 +194,22 @@ class UniqueContentRule(models.Model): return self.name +# region Discord Channel + +class DiscordChannel(models.Model): + """ + Store limited data on a relevant Channel from Discord, used to indicate + where subscriptions should send content to. Instance creation & deletion + is handled internally, when Subscriptions are modified. + """ + + id = models.AutoField(primary_key=True) + channel_id = models.BigIntegerField() + + def __str__(self): + return str(self.channel_id) + + # region Subscription class Subscription(models.Model): @@ -210,6 +229,7 @@ class Subscription(models.Model): active = models.BooleanField(default=True) publish_threshold = models.DateTimeField(default=timezone.now) + channels = models.ManyToManyField(to=DiscordChannel, related_name="subscriptions", blank=True) filters = models.ManyToManyField(to=ContentFilter, blank=True) message_style = models.ForeignKey(to=MessageStyle, on_delete=models.SET_NULL, null=True, blank=True) unique_rules = models.ManyToManyField(to=UniqueContentRule, blank=False)