Merge timelineevent, urls and post type migration

This commit is contained in:
Andrew Godwin 2022-12-18 09:22:15 -07:00
parent a408cbaa27
commit 35102fbdd4
4 changed files with 90 additions and 36 deletions

View file

@ -323,6 +323,7 @@ class Migration(migrations.Migration):
("liked", "Liked"),
("followed", "Followed"),
("boosted", "Boosted"),
("announcement", "Announcement"),
],
max_length=100,
),

View file

@ -1,36 +0,0 @@
# Generated by Django 4.1.4 on 2022-12-16 02:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("activities", "0004_emoji_post_emojis"),
]
operations = [
migrations.AddField(
model_name="post",
name="type",
field=models.CharField(
choices=[
("Article", "Article"),
("Audio", "Audio"),
("Event", "Event"),
("Image", "Image"),
("Note", "Note"),
("Page", "Page"),
("Question", "Question"),
("Video", "Video"),
],
default="Note",
max_length=20,
),
),
migrations.AddField(
model_name="post",
name="type_data",
field=models.JSONField(blank=True, null=True),
),
]

View file

@ -0,0 +1,85 @@
# Generated by Django 4.1.4 on 2022-12-16 02:52
import datetime
from django.db import migrations, models
def timeline_event_populate(apps, schema_editor):
"""
Populates all timeline events with a published date before 2001
with their created date instead
"""
TimelineEvent = apps.get_model("activities", "timelineevent")
TimelineEvent.objects.filter(
published__lt=datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc)
).update(published=models.F("created"))
class Migration(migrations.Migration):
dependencies = [
("activities", "0004_emoji_post_emojis"),
]
operations = [
migrations.AddField(
model_name="post",
name="type",
field=models.CharField(
choices=[
("Article", "Article"),
("Audio", "Audio"),
("Event", "Event"),
("Image", "Image"),
("Note", "Note"),
("Page", "Page"),
("Question", "Question"),
("Video", "Video"),
],
default="Note",
max_length=20,
),
),
migrations.AddField(
model_name="post",
name="type_data",
field=models.JSONField(blank=True, null=True),
),
migrations.AddField(
model_name="timelineevent",
name="published",
field=models.DateTimeField(
default=datetime.datetime(
2000, 1, 1, 0, 0, tzinfo=datetime.timezone.utc
)
),
preserve_default=False,
),
migrations.AddField(
model_name="timelineevent",
name="seen",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="post",
name="object_uri",
field=models.CharField(blank=True, max_length=2048, null=True, unique=True),
),
migrations.AlterField(
model_name="post",
name="type_data",
field=models.JSONField(
blank=True,
null=True,
),
),
migrations.AlterField(
model_name="post",
name="url",
field=models.CharField(blank=True, max_length=2048, null=True),
),
migrations.RunPython(
code=timeline_event_populate,
reverse_code=lambda a, s: None,
),
]

View file

@ -16,6 +16,7 @@ class TimelineEvent(models.Model):
liked = "liked" # Someone liking one of our posts
followed = "followed"
boosted = "boosted" # Someone boosting one of our posts
announcement = "announcement" # Server announcement
# The user this event is for
identity = models.ForeignKey(
@ -50,6 +51,9 @@ class TimelineEvent(models.Model):
related_name="timeline_events_about_us",
)
published = models.DateTimeField()
seen = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
class Meta: