upgrade.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ===============================================
  2. Upgrading from Django's previous comment system
  3. ===============================================
  4. Prior versions of Django included an outdated, undocumented comment system. Users who reverse-engineered this framework will need to upgrade to use the
  5. new comment system; this guide explains how.
  6. The main changes from the old system are:
  7. * This new system is documented.
  8. * It uses modern Django features like :doc:`forms </topics/forms/index>` and
  9. :doc:`modelforms </topics/forms/modelforms>`.
  10. * It has a single ``Comment`` model instead of separate ``FreeComment`` and
  11. ``Comment`` models.
  12. * Comments have "email" and "URL" fields.
  13. * No ratings, photos and karma. This should only effect World Online.
  14. * The ``{% comment_form %}`` tag no longer exists. Instead, there's now two
  15. functions: ``{% get_comment_form %}``, which returns a form for posting a
  16. new comment, and ``{% render_comment_form %}``, which renders said form
  17. using the ``comments/form.html`` template.
  18. * The way comments are include in your URLconf have changed; you'll need to
  19. replace::
  20. (r'^comments/', include('django.contrib.comments.urls.comments')),
  21. with::
  22. (r'^comments/', include('django.contrib.comments.urls')),
  23. Upgrading data
  24. --------------
  25. The data models for Django's comment system have changed, as have the
  26. table names. Before you transfer your existing data into the new comments
  27. system, make sure that you have installed the new comments system as
  28. explained in the
  29. :doc:`quick start guide </ref/contrib/comments/index>`.
  30. This will ensure that the new tables have been properly created.
  31. To transfer your data into the new comments system, you'll need to directly
  32. run the following SQL:
  33. .. code-block:: sql
  34. BEGIN;
  35. INSERT INTO django_comments
  36. (content_type_id, object_pk, site_id, user_name, user_email, user_url,
  37. comment, submit_date, ip_address, is_public, is_removed)
  38. SELECT
  39. content_type_id, object_id, site_id, person_name, '', '', comment,
  40. submit_date, ip_address, is_public, not approved
  41. FROM comments_freecomment;
  42. INSERT INTO django_comments
  43. (content_type_id, object_pk, site_id, user_id, user_name, user_email,
  44. user_url, comment, submit_date, ip_address, is_public, is_removed)
  45. SELECT
  46. content_type_id, object_id, site_id, user_id, '', '', '', comment,
  47. submit_date, ip_address, is_public, is_removed
  48. FROM comments_comment;
  49. UPDATE django_comments SET user_name = (
  50. SELECT username FROM auth_user
  51. WHERE django_comments.user_id = auth_user.id
  52. ) WHERE django_comments.user_id is not NULL;
  53. UPDATE django_comments SET user_email = (
  54. SELECT email FROM auth_user
  55. WHERE django_comments.user_id = auth_user.id
  56. ) WHERE django_comments.user_id is not NULL;
  57. COMMIT;