Skip to content

Commit

Permalink
refactor: article title handling in load_edits command
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoleoncio committed Oct 10, 2024
1 parent efdeee7 commit ab28055
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 4 additions & 2 deletions contests/management/commands/load_edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def handle(self, *args, **options):
for item in list_:
article, created = Article.objects.get_or_create(
contest=contest,
articleID=item['id'],
title=item['title'],
articleID=item['pageid'],
)
if not created:
article.active = True
article.save(update_fields=['active'])
if article.title == '' or article.title != item['title']:
article.title = item['title']
article.save(update_fields=['title'])

# Coleta lista de revisões já inseridas no banco de dados
existing_revisions = Edit.objects.filter(contest=contest).values_list('diff', flat=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.1 on 2024-10-10 16:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('contests', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='article',
name='title',
field=models.TextField(default=''),
),
migrations.AlterUniqueTogether(
name='article',
unique_together={('contest', 'articleID')},
),
]
5 changes: 4 additions & 1 deletion contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ class Meta:
class Article(models.Model):
contest = models.ForeignKey('Contest', on_delete=models.CASCADE)
articleID = models.IntegerField()
title = models.TextField()
title = models.TextField(default='')
active = models.BooleanField(default=True)

def __str__(self):
return (f"{self.contest.name_id} - {self.articleID} - {self.title}")

class Meta:
unique_together = ['contest', 'articleID']


class Participant(models.Model):
contest = models.ForeignKey('Contest', on_delete=models.CASCADE)
Expand Down

0 comments on commit ab28055

Please sign in to comment.