-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump django-taggit to 6.1.0 * Curate list of existing tags * remove merging of fuzzy-matching tags --------- Co-authored-by: Ryan Johnson <[email protected]>
- Loading branch information
1 parent
9915962
commit 99e0c88
Showing
3 changed files
with
45 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.16 on 2024-11-05 05:32 | ||
from django.db import migrations | ||
|
||
|
||
def remove_orphaned_and_archived_tags(apps, schema_editor): | ||
Tag = apps.get_model("taggit", "Tag") | ||
TaggedItem = apps.get_model("taggit", "TaggedItem") | ||
Question = apps.get_model("questions", "Question") | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
|
||
orphaned_tags = Tag.objects.filter(taggit_taggeditem_items__isnull=True) | ||
orphaned_tags.delete() | ||
|
||
question_content_type = ContentType.objects.get_for_model(Question) | ||
archived_tag_ids = TaggedItem.objects.filter( | ||
content_type=question_content_type, | ||
object_id__in=Question.objects.filter(is_archived=True).values_list("id", flat=True), | ||
).values_list("tag_id", flat=True) | ||
|
||
non_archived_tag_ids = TaggedItem.objects.filter( | ||
content_type=question_content_type, | ||
object_id__in=Question.objects.filter(is_archived=False).values_list("id", flat=True), | ||
).values_list("tag_id", flat=True) | ||
|
||
exclusively_archived_tag_ids = set(archived_tag_ids) - set(non_archived_tag_ids) | ||
exclusively_archived_tags = Tag.objects.filter(id__in=exclusively_archived_tag_ids) | ||
exclusively_archived_tags.delete() | ||
|
||
|
||
def backwards(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("questions", "0017_question_update_topic_counter"), | ||
] | ||
|
||
operations = [migrations.RunPython(remove_orphaned_and_archived_tags, backwards)] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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