Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

Commit

Permalink
Add db_index=True to object_pk and is_removed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov authored and ObserverOfTime committed Jan 4, 2021
1 parent 4cd8ee5 commit a65b7bb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ History
* Forked and rebranded into ``django-commentary``.
* Dropped support for Python<3.6 and Django<3.0.
* Added the ``delete_stale_comments`` management command.
* Added db_index to ``object_pk`` and ``is_removed`` fields.

1.9.1 (2019-02-20)
------------------
Expand Down
4 changes: 2 additions & 2 deletions commentary/abstracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BaseCommentAbstractModel(models.Model):
ContentType, verbose_name=_('content type'),
related_name='content_type_set_for_%(class)s', on_delete=models.CASCADE
)
object_pk = models.CharField(_('object ID'), max_length=255)
object_pk = models.CharField(_('object ID'), max_length=64, db_index=True)
content_object = GenericForeignKey(
ct_field='content_type', fk_field='object_pk'
)
Expand All @@ -43,7 +43,7 @@ class BaseCommentAbstractModel(models.Model):
)
)
is_removed = models.BooleanField(
_('is removed'), default=False, help_text=_(
_('is removed'), default=False, db_index=True, help_text=_(
'Check this box if the comment is inappropriate. A "This '
'comment has been removed" message will be displayed instead.'
)
Expand Down
34 changes: 34 additions & 0 deletions commentary/migrations/0005_add_db_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('commentary', '0004_commentary'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='is_removed',
field=models.BooleanField(
db_index=True, default=False, help_text=(
'Check this box if the comment is inappropriate.'
' A "This comment has been removed" message'
' will be displayed instead.'
), verbose_name='is removed'),
),
migrations.AlterField(
model_name='comment',
name='object_pk',
field=models.CharField(
db_index=True, max_length=64, verbose_name='object ID'
),
),
migrations.AlterUniqueTogether(
name='commentflag',
unique_together={('user', 'comment', 'flag')},
),
]
4 changes: 2 additions & 2 deletions docs/models.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ The comment models

.. attribute:: object_pk

A :class:`~django.db.models.TextField` containing the primary
key of the object the comment is attached to.
A :class:`~django.db.models.CharField` containing the primary
key of the object the comment is attached to. ``max_length=64``.

.. attribute:: site

Expand Down

0 comments on commit a65b7bb

Please sign in to comment.