Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 5.2.7 on 2025-11-17 22:44

from django.conf import settings
from django.db import migrations
from django.db.models import Count

def cleanup_duplicate_proposals(apps, schema_editor):
AlgorithmTagProposal = apps.get_model('problems', 'AlgorithmTagProposal')
DifficultyTagProposal = apps.get_model('problems', 'DifficultyTagProposal')

# Cleanup AlgorithmTagProposal
duplicates = (
AlgorithmTagProposal.objects.values('problem', 'tag', 'user')
.annotate(count=Count('id'))
.filter(count__gt=1)
)

for duplicate in duplicates:
proposals = AlgorithmTagProposal.objects.filter(
problem=duplicate['problem'],
tag=duplicate['tag'],
user=duplicate['user']
).order_by('id')

# Keep the first one, delete the rest
for proposal in proposals[1:]:
proposal.delete()

# Cleanup DifficultyTagProposal
duplicates = (
DifficultyTagProposal.objects.values('problem', 'user')
.annotate(count=Count('id'))
.filter(count__gt=1)
)

for duplicate in duplicates:
proposals = DifficultyTagProposal.objects.filter(
problem=duplicate['problem'],
user=duplicate['user']
).order_by('id')

# Keep the first one, delete the rest
for proposal in proposals[1:]:
proposal.delete()


class Migration(migrations.Migration):

dependencies = [
('problems', '0038_alter_algorithmtaglocalization_language_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.RunPython(cleanup_duplicate_proposals),
migrations.AlterUniqueTogether(
name='algorithmtagproposal',
unique_together={('problem', 'tag', 'user')},
),
migrations.AlterUniqueTogether(
name='difficultytagproposal',
unique_together={('problem', 'user')},
),
]
2 changes: 2 additions & 0 deletions oioioi/problems/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ def __str__(self):
return str(self.problem.name) + " -- " + str(self.tag.name)

class Meta:
unique_together = ("problem", "user")
verbose_name = _("difficulty proposal")
verbose_name_plural = _("difficulty proposals")

Expand Down Expand Up @@ -878,6 +879,7 @@ def __str__(self):
return str(self.problem.name) + " -- " + str(self.tag.name)

class Meta:
unique_together = ("problem", "tag", "user")
verbose_name = _("algorithm tag proposal")
verbose_name_plural = _("algorithm tag proposals")

Expand Down
Loading