discord-channel and style auto created field
This commit is contained in:
parent
1c4efd0da2
commit
024a26325b
@ -158,8 +158,10 @@ class MessageStyleSerializer(DynamicModelSerializer):
|
|||||||
"show_images",
|
"show_images",
|
||||||
"fetch_images",
|
"fetch_images",
|
||||||
"title_mutator",
|
"title_mutator",
|
||||||
"description_mutator"
|
"description_mutator",
|
||||||
|
"auto_created"
|
||||||
)
|
)
|
||||||
|
read_only_fields = ("auto_created",)
|
||||||
|
|
||||||
|
|
||||||
class UniqueContentRuleSerializer(DynamicModelSerializer):
|
class UniqueContentRuleSerializer(DynamicModelSerializer):
|
||||||
|
@ -7,6 +7,7 @@ from .models import (
|
|||||||
ContentFilter,
|
ContentFilter,
|
||||||
MessageMutator,
|
MessageMutator,
|
||||||
MessageStyle,
|
MessageStyle,
|
||||||
|
DiscordChannel,
|
||||||
Subscription,
|
Subscription,
|
||||||
Content,
|
Content,
|
||||||
UniqueContentRule
|
UniqueContentRule
|
||||||
@ -52,7 +53,16 @@ class MessageStyleAdmin(admin.ModelAdmin):
|
|||||||
"show_images",
|
"show_images",
|
||||||
"fetch_images",
|
"fetch_images",
|
||||||
"title_mutator",
|
"title_mutator",
|
||||||
"description_mutator"
|
"description_mutator",
|
||||||
|
"auto_created"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(DiscordChannel)
|
||||||
|
class DiscordChannelAdmin(admin.ModelAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id",
|
||||||
|
"channel_id"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -138,13 +138,15 @@ class MessageStyle(models.Model):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
auto_created = models.BooleanField(default=False, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "message style"
|
verbose_name = "message style"
|
||||||
verbose_name_plural = "message styles"
|
verbose_name_plural = "message styles"
|
||||||
get_latest_by = "id"
|
get_latest_by = "id"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.server.name} - {self.id}"
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Server)
|
@receiver(post_save, sender=Server)
|
||||||
@ -165,7 +167,8 @@ def create_default_items(sender, instance, created, **kwargs):
|
|||||||
show_images=True,
|
show_images=True,
|
||||||
fetch_images=True,
|
fetch_images=True,
|
||||||
title_mutator=None,
|
title_mutator=None,
|
||||||
description_mutator=None
|
description_mutator=None,
|
||||||
|
auto_created=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -191,6 +194,22 @@ class UniqueContentRule(models.Model):
|
|||||||
return self.name
|
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
|
# region Subscription
|
||||||
|
|
||||||
class Subscription(models.Model):
|
class Subscription(models.Model):
|
||||||
@ -210,6 +229,7 @@ class Subscription(models.Model):
|
|||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
publish_threshold = models.DateTimeField(default=timezone.now)
|
publish_threshold = models.DateTimeField(default=timezone.now)
|
||||||
|
channels = models.ManyToManyField(to=DiscordChannel, related_name="subscriptions", blank=True)
|
||||||
filters = models.ManyToManyField(to=ContentFilter, blank=True)
|
filters = models.ManyToManyField(to=ContentFilter, blank=True)
|
||||||
message_style = models.ForeignKey(to=MessageStyle, on_delete=models.SET_NULL, null=True, 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)
|
unique_rules = models.ManyToManyField(to=UniqueContentRule, blank=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user