1
from django.core.management.base import BaseCommand
2
from django.contrib.comments.models import Comment, FreeComment
3
from threadedcomments.models import ThreadedComment, FreeThreadedComment
5
class Command(BaseCommand):
6
help = "Migrates Django's built-in django.contrib.comments data to threadedcomments data"
8
output_transaction = True
10
def handle(self, *args, **options):
12
Converts all legacy ``Comment`` and ``FreeComment`` objects into
13
``ThreadedComment`` and ``FreeThreadedComment`` objects, respectively.
15
self.handle_free_comments()
16
self.handle_comments()
18
def handle_free_comments(self):
20
Converts all legacy ``FreeComment`` objects into ``FreeThreadedComment``
23
comments = FreeComment.objects.all()
25
new = FreeThreadedComment(
26
content_type = c.content_type,
27
object_id = c.object_id,
32
date_submitted = c.submit_date,
33
date_modified = c.submit_date,
34
date_approved = c.submit_date,
35
is_public = c.is_public,
36
ip_address = c.ip_address,
37
is_approved = c.approved
41
def handle_comments(self):
43
Converts all legacy ``Comment`` objects into ``ThreadedComment`` objects.
45
comments = Comment.objects.all()
47
new = ThreadedComment(
48
content_type = c.content_type,
49
object_id = c.object_id,
52
date_submitted = c.submit_date,
53
date_modified = c.submit_date,
54
date_approved = c.submit_date,
55
is_public = c.is_public,
56
ip_address = c.ip_address,
57
is_approved = not c.is_removed
b'\\ No newline at end of file'