From 044f5a030daaa00bf7295d7867e97129e136a205 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 27 Apr 2023 17:01:05 -0400 Subject: [PATCH] add recent_check field to link needed to facilitate sorting of links by test results --- doab_check/check.py | 2 ++ .../migrations/0003_link_recent_check.py | 19 ++++++++++++++++++ .../migrations/0004_auto_20230427_1818.py | 20 +++++++++++++++++++ doab_check/models.py | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 doab_check/migrations/0003_link_recent_check.py create mode 100644 doab_check/migrations/0004_auto_20230427_1818.py diff --git a/doab_check/check.py b/doab_check/check.py index 5640eb6..69d7ef2 100755 --- a/doab_check/check.py +++ b/doab_check/check.py @@ -118,5 +118,7 @@ def check_link(link): check.return_code = code check.content_type = ct check.save() + check.link.recent_check = check + check.link.save() diff --git a/doab_check/migrations/0003_link_recent_check.py b/doab_check/migrations/0003_link_recent_check.py new file mode 100644 index 0000000..a10af2a --- /dev/null +++ b/doab_check/migrations/0003_link_recent_check.py @@ -0,0 +1,19 @@ +# Generated by Django 4.1.7 on 2023-04-27 18:10 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('doab_check', '0002_alter_check_content_type'), + ] + + operations = [ + migrations.AddField( + model_name='link', + name='recent_check', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='checked_link', to='doab_check.check'), + ), + ] diff --git a/doab_check/migrations/0004_auto_20230427_1818.py b/doab_check/migrations/0004_auto_20230427_1818.py new file mode 100644 index 0000000..37ff429 --- /dev/null +++ b/doab_check/migrations/0004_auto_20230427_1818.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.7 on 2023-04-27 18:18 + +from django.db import migrations + + +def populate_recent(apps, schema_editor): + Check = apps.get_model("doab_check", "Check") + for check in Check.objects.order_by('created'): + check.link.recent_check = check + check.link.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('doab_check', '0003_link_recent_check'), + ] + + operations = [ + migrations.RunPython(populate_recent), + ] diff --git a/doab_check/models.py b/doab_check/models.py index 108c03a..9aedbfb 100644 --- a/doab_check/models.py +++ b/doab_check/models.py @@ -40,6 +40,12 @@ class Link(models.Model): # derived from url so we can do sorting, etc. provider = models.CharField(max_length=255, default='') + recent_check = models.ForeignKey("Check", null=True, related_name='checked_link', + on_delete=models.SET_NULL) + + def recent_checks(self): + return self.checks.order_by('-created') + def save(self, *args, **kwargs): if self.url: netloc = urlparse(self.url).netloc.lower()