diff --git a/collection/migrations/0008_auto_20190828_0450.py b/collection/migrations/0008_auto_20190828_0450.py new file mode 100644 index 0000000..ad258b5 --- /dev/null +++ b/collection/migrations/0008_auto_20190828_0450.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.1 on 2019-08-28 04:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('collection', '0007_auto_20181008_2042'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='collection', + unique_together=set(), + ), + ] diff --git a/collection/migrations/0009_auto_20190828_0457.py b/collection/migrations/0009_auto_20190828_0457.py new file mode 100644 index 0000000..4685fa6 --- /dev/null +++ b/collection/migrations/0009_auto_20190828_0457.py @@ -0,0 +1,15 @@ +# Generated by Django 2.0.1 on 2019-08-28 04:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('collection', '0008_auto_20190828_0450'), + ] + + operations = [ + migrations.RunSQL( + "CREATE UNIQUE INDEX collection_collection_title_text_type_id_uniq ON collection_collection (title, md5(text), type_id)"), + ] diff --git a/collection/models.py b/collection/models.py index c794b15..bc02d2a 100644 --- a/collection/models.py +++ b/collection/models.py @@ -82,5 +82,3 @@ def repl(match): text = Sentence(text=self.text).html # convert words to links return re.sub(r"{{sentence:([0-9]+)}}", repl, text, flags=re.MULTILINE) - class Meta: - unique_together = ('title', 'text', 'type',) diff --git a/collection/views.py b/collection/views.py index 83346d8..9bfd3e0 100644 --- a/collection/views.py +++ b/collection/views.py @@ -60,7 +60,10 @@ def keyword_filtered(request): # eg. poem collection_type = first_collection_obj.type # eg. all poems - collections = Collection.objects.filter(type=collection_type) + collections = [] + for collection_type in Collection.objects.all().distinct("type"): + collection_sample = Collection.objects.filter(type=collection_type.type).order_by("-id")[0:3] + collections.extend(list(collection_sample)) context["collections"] = collections context["active_collection"] = collection_type # to delete
from html text