feat(blog): expand publishing and moderation APIs
This commit is contained in:
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