Added server_id to FeedChannel model

possibly violates normal form?
This commit is contained in:
Corban-Lee Jones 2024-01-31 11:51:15 +00:00
parent 765c5b4d9f
commit 7dd8b8f6e8
6 changed files with 51 additions and 64 deletions

View File

@ -104,21 +104,21 @@ class DynamicModelSerializer(serializers.HyperlinkedModelSerializer):
abstract = True
class RssFeedSerializer(DynamicModelSerializer):
class RssFeedSerializer( DynamicModelSerializer):
image = serializers.ImageField()
class Meta:
model = RSSFeed
fields = (
"uuid", "name", "url", "image", "created_at"
"uuid", "name", "url", "image", "discord_server_id", "created_at"
)
class FeedChannelSerializer(DynamicModelSerializer):
feeds = RssFeedSerializer(many=True)
feeds = RssFeedSerializer(many=True)# , queryset=RSSFeed.objects.all())
class Meta:
model = FeedChannel
fields = (
"uuid", "channel_id", "feeds", "created_at"
"uuid", "discord_server_id", "discord_channel_id", "feeds", "created_at"
)

View File

@ -6,14 +6,14 @@ from .models import RSSFeed, FeedChannel
class RSSFeedAdmin(admin.ModelAdmin):
list_display = ["uuid", "name", "url", "created_at"]
list_display = ["uuid", "name", "url", "discord_server_id", "created_at"]
admin.site.register(RSSFeed, RSSFeedAdmin)
class FeedChannelAdmin(admin.ModelAdmin):
list_display = ["uuid", "channel_id", "created_at"]
list_display = ["uuid", "discord_server_id", "discord_channel_id", "created_at"]
admin.site.register(FeedChannel, FeedChannelAdmin)

View File

@ -1,4 +1,4 @@
# Generated by Django 5.0.1 on 2024-01-24 16:12
# Generated by Django 5.0.1 on 2024-01-30 20:45
import apps.home.models
import django.utils.timezone
@ -14,17 +14,41 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='FeedChannel',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('discord_server_id', models.PositiveBigIntegerField(help_text='the discord server id of this item', verbose_name='discord server id')),
('discord_channel_id', models.PositiveBigIntegerField(help_text='the discord channel id of this item', verbose_name='discord channel id')),
('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='when this item was created', verbose_name='creation date & time')),
],
options={
'verbose_name': 'Feed Channel',
'verbose_name_plural': 'Feed Channels',
},
),
migrations.CreateModel(
name='RSSFeed',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(help_text='a human readable nickname for this item', max_length=120, verbose_name='name')),
('url', models.URLField(help_text='url to the RSS feed', validators=[apps.home.models.validate_rss_url], verbose_name='url')),
('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='when this item was created', verbose_name='created at')),
('url', models.URLField(help_text='url to the RSS feed', verbose_name='url')),
('image', models.ImageField(blank=True, help_text='image of the RSS feed', null=True, storage=apps.home.models.OverwriteStorage(), upload_to=apps.home.models.RSSFeedIconPathGenerator(), verbose_name='image')),
('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='when this item was created', verbose_name='creation date & time')),
('discord_server_id', models.PositiveBigIntegerField(help_text='the discord server id of this item', verbose_name='discord server id')),
],
options={
'verbose_name': 'RSS Feed',
'verbose_name_plural': 'RSS Feeds',
},
),
migrations.AddConstraint(
model_name='rssfeed',
constraint=models.UniqueConstraint(fields=('name', 'discord_server_id'), name='unique name & server pair'),
),
migrations.AddField(
model_name='feedchannel',
name='feeds',
field=models.ManyToManyField(help_text='the feeds to include in this item', related_name='queues', to='home.rssfeed', verbose_name='feeds'),
),
]

View File

@ -1,33 +0,0 @@
# Generated by Django 5.0.1 on 2024-01-24 17:08
import django.utils.timezone
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='rssfeed',
name='created_at',
field=models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='when this item was created', verbose_name='creation date & time'),
),
migrations.CreateModel(
name='FeedChannel',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('channel_id', models.PositiveBigIntegerField(help_text='the id of the discord channel', verbose_name='discord channel id')),
('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='when this item was created', verbose_name='creation date & time')),
('feeds', models.ManyToManyField(help_text='the feeds to include in this item', to='home.rssfeed', verbose_name='feeds')),
],
options={
'verbose_name': 'Feed Channel',
'verbose_name_plural': 'Feed Channels',
},
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 5.0.1 on 2024-01-28 22:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0002_alter_rssfeed_created_at_feedchannel'),
]
operations = [
migrations.AddField(
model_name='rssfeed',
name='image',
field=models.ImageField(blank=True, help_text='image of the RSS feed', null=True, upload_to='', verbose_name='image'),
),
]

View File

@ -100,9 +100,17 @@ class RSSFeed(models.Model):
editable=False
)
discord_server_id = models.PositiveBigIntegerField(
verbose_name=_("discord server id"),
help_text=_("the discord server id of this item")
)
class Meta:
verbose_name = _("RSS Feed")
verbose_name_plural = _("RSS Feeds")
constraints = [
models.UniqueConstraint(fields=["name", "discord_server_id"], name="unique name & server pair")
]
def __str__(self):
return self.name
@ -113,16 +121,22 @@ class FeedChannel(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
channel_id = models.PositiveBigIntegerField(
discord_server_id = models.PositiveBigIntegerField(
verbose_name=_("discord server id"),
help_text=_("the discord server id of this item")
)
discord_channel_id = models.PositiveBigIntegerField(
verbose_name=_("discord channel id"),
help_text=_("the id of the discord channel"),
help_text=_("the discord channel id of this item"),
null=False, blank=False
)
feeds = models.ManyToManyField(
to=RSSFeed,
verbose_name=_("feeds"),
help_text=_("the feeds to include in this item")
help_text=_("the feeds to include in this item"),
related_name=_("queues")
)
created_at = models.DateTimeField(
@ -137,4 +151,4 @@ class FeedChannel(models.Model):
verbose_name_plural = _("Feed Channels")
def __str__(self):
return str(self.channel_id)
return str(self.discord_channel_id)