1
from django.core.management.base import BaseCommand
2
from django.contrib.comments.models import Comment, FreeComment
3
from threadedcomments.models import ThreadedComment, FreeThreadedComment
6
class Command(BaseCommand):
7
help = "Migrates Django's built-in django.contrib.comments data to threadedcomments data"
9
output_transaction = True
11
def handle(self, *args, **options):
12
"""Converts all legacy ``Comment`` and ``FreeComment`` objects into
13
``ThreadedComment`` and ``FreeThreadedComment`` objects,
15
self.handle_free_comments()
16
self.handle_comments()
18
def handle_free_comments(self):
19
"""Converts all legacy ``FreeComment`` objects into
20
``FreeThreadedComment`` objects."""
21
comments = FreeComment.objects.all()
23
new = FreeThreadedComment(
24
content_type=c.content_type,
25
object_id=c.object_id,
30
date_submitted=c.submit_date,
31
date_modified=c.submit_date,
32
date_approved=c.submit_date,
33
is_public=c.is_public,
34
ip_address=c.ip_address,
35
is_approved=c.approved
39
def handle_comments(self):
40
"""Converts all legacy ``Comment`` objects into ``ThreadedComment``
42
comments = Comment.objects.all()
44
new = ThreadedComment(
45
content_type=c.content_type,
46
object_id=c.object_id,
49
date_submitted=c.submit_date,
50
date_modified=c.submit_date,
51
date_approved=c.submit_date,
52
is_public=c.is_public,
53
ip_address=c.ip_address,
54
is_approved=not c.is_removed