feat(blog): expand publishing and moderation APIs
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import apps.blog.models
|
||||
|
||||
|
||||
def backfill_post_writers(apps, schema_editor):
|
||||
Post = apps.get_model("blog", "Post")
|
||||
for post in Post.objects.exclude(author_id__isnull=True).iterator():
|
||||
post.writers.add(post.author_id)
|
||||
|
||||
|
||||
def noop_reverse(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("blog", "0003_blog_platform"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="BlogBanner",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
("is_deleted", models.BooleanField(default=False)),
|
||||
("deleted_at", models.DateTimeField(blank=True, null=True)),
|
||||
("title", models.CharField(blank=True, max_length=160)),
|
||||
("alt_text", models.CharField(blank=True, max_length=200)),
|
||||
("image", models.ImageField(upload_to=apps.blog.models.blog_banner_upload_to)),
|
||||
("url", models.URLField()),
|
||||
("is_active", models.BooleanField(default=True)),
|
||||
("sort_order", models.PositiveIntegerField(default=0)),
|
||||
],
|
||||
options={
|
||||
"ordering": ["sort_order", "-created_at"],
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="category",
|
||||
name="parent",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="children",
|
||||
to="blog.category",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="post",
|
||||
name="writers",
|
||||
field=models.ManyToManyField(
|
||||
blank=True,
|
||||
related_name="written_blog_posts",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="blogbanner",
|
||||
index=models.Index(fields=["is_active", "sort_order"], name="blog_blogba_is_acti_c11b3c_idx"),
|
||||
),
|
||||
migrations.RunPython(backfill_post_writers, noop_reverse),
|
||||
]
|
||||
58
apps/blog/migrations/0005_comment_hide_delete_state.py
Normal file
58
apps/blog/migrations/0005_comment_hide_delete_state.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def mark_legacy_hidden_comments(apps, schema_editor):
|
||||
Comment = apps.get_model("blog", "Comment")
|
||||
Comment.objects.filter(is_approved=False, is_deleted=False).update(is_hidden=True)
|
||||
|
||||
|
||||
def unmark_legacy_hidden_comments(apps, schema_editor):
|
||||
Comment = apps.get_model("blog", "Comment")
|
||||
Comment.objects.filter(is_hidden=True, is_deleted=False).update(is_hidden=False)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("blog", "0004_blog_banner_nested_categories_post_writers"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="comment",
|
||||
name="delete_note",
|
||||
field=models.TextField(blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="comment",
|
||||
name="deleted_by",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="deleted_blog_comments",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="comment",
|
||||
name="is_hidden",
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.RunPython(mark_legacy_hidden_comments, unmark_legacy_hidden_comments),
|
||||
migrations.RemoveIndex(
|
||||
model_name="comment",
|
||||
name="blog_commen_post_id_7710b1_idx",
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="comment",
|
||||
index=models.Index(fields=["post", "is_approved", "is_hidden"], name="blog_commen_post_id_760827_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="comment",
|
||||
index=models.Index(fields=["parent", "is_deleted", "is_hidden"], name="blog_commen_parent__2abfc7_idx"),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user