1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
from django.core.management.base import BaseCommand
from django.contrib.comments.models import Comment, FreeComment
from threadedcomments.models import ThreadedComment, FreeThreadedComment
class Command(BaseCommand):
help = "Migrates Django's built-in django.contrib.comments data to threadedcomments data"
output_transaction = True
def handle(self, *args, **options):
"""
Converts all legacy ``Comment`` and ``FreeComment`` objects into
``ThreadedComment`` and ``FreeThreadedComment`` objects, respectively.
"""
self.handle_free_comments()
self.handle_comments()
def handle_free_comments(self):
"""
Converts all legacy ``FreeComment`` objects into ``FreeThreadedComment``
objects.
"""
comments = FreeComment.objects.all()
for c in comments:
new = FreeThreadedComment(
content_type = c.content_type,
object_id = c.object_id,
comment = c.comment,
name = c.person_name,
website = '',
email = '',
date_submitted = c.submit_date,
date_modified = c.submit_date,
date_approved = c.submit_date,
is_public = c.is_public,
ip_address = c.ip_address,
is_approved = c.approved
)
new.save()
def handle_comments(self):
"""
Converts all legacy ``Comment`` objects into ``ThreadedComment`` objects.
"""
comments = Comment.objects.all()
for c in comments:
new = ThreadedComment(
content_type = c.content_type,
object_id = c.object_id,
comment = c.comment,
user = c.user,
date_submitted = c.submit_date,
date_modified = c.submit_date,
date_approved = c.submit_date,
is_public = c.is_public,
ip_address = c.ip_address,
is_approved = not c.is_removed
)
new.save()
|