forked from honzakral/django-threadedcomments
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.core.management.base import NoArgsCommand | ||
from django.contrib import comments | ||
from django.db import transaction, connection | ||
from django.conf import settings | ||
|
||
PATH_SEPARATOR = getattr(settings, 'COMMENT_PATH_SEPARATOR', '/') | ||
PATH_DIGITS = getattr(settings, 'COMMENT_PATH_DIGITS', 10) | ||
|
||
SQL = """ | ||
INSERT INTO threadedcomments_comment(comment_ptr_id, tree_path) VALUES(%s, %s) | ||
""" | ||
|
||
class Command(NoArgsCommand): | ||
help = "Migrates from django.contrib.comments to django-threadedcomments" | ||
|
||
def handle(self, *args, **options): | ||
transaction.commit_unless_managed() | ||
transaction.enter_transaction_management() | ||
transaction.managed(True) | ||
|
||
cursor = connection.cursor() | ||
|
||
for comment in comments.models.Comment.objects.all(): | ||
cursor.execute(SQL, [comment.id, '']) | ||
|
||
transaction.commit() | ||
transaction.leave_transaction_management() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters