diff --git a/HISTORY.rst b/HISTORY.rst index c9d0094..85bdbac 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ------------------ diff --git a/commentary/abstracts.py b/commentary/abstracts.py index 593f0d0..e75f4e4 100644 --- a/commentary/abstracts.py +++ b/commentary/abstracts.py @@ -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' ) @@ -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.' ) diff --git a/commentary/migrations/0005_add_db_indexes.py b/commentary/migrations/0005_add_db_indexes.py new file mode 100644 index 0000000..d956f0a --- /dev/null +++ b/commentary/migrations/0005_add_db_indexes.py @@ -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')}, + ), + ] diff --git a/docs/models.txt b/docs/models.txt index d385caf..eb40a55 100644 --- a/docs/models.txt +++ b/docs/models.txt @@ -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