diff options
author | 2020-12-22 00:06:25 +0100 | |
---|---|---|
committer | 2020-12-22 00:06:25 +0100 | |
commit | c68b0904a73b4b66ee6b5e50b806a4074b08c002 (patch) | |
tree | 6ef67102269f87ee5970ff8b0b19f256a400f83d /pydis_site/apps/home | |
parent | Merge pull request #439 from python-discord/ks123/sentry (diff) |
Make last_updated field automatically update.
Previously, we were operating under a bad assumption that we would be
updating the last_updated field in the RepositoryMetadata objects
whenever we updated the objects with new data from the GitHub API.
Upon closer inspection, this is not at all what we're doing, and some of
those repository objects had not been updated in over a year!
This introduces `auto_now` to the field, which will ensure that it is
automatically updated whenever the object is updated.
Diffstat (limited to 'pydis_site/apps/home')
-rw-r--r-- | pydis_site/apps/home/migrations/0002_auto_now_on_repository_metadata.py | 18 | ||||
-rw-r--r-- | pydis_site/apps/home/models/repository_metadata.py | 15 |
2 files changed, 25 insertions, 8 deletions
diff --git a/pydis_site/apps/home/migrations/0002_auto_now_on_repository_metadata.py b/pydis_site/apps/home/migrations/0002_auto_now_on_repository_metadata.py new file mode 100644 index 00000000..7e78045b --- /dev/null +++ b/pydis_site/apps/home/migrations/0002_auto_now_on_repository_metadata.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.11 on 2020-12-21 22:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='repositorymetadata', + name='last_updated', + field=models.DateTimeField(auto_now=True, help_text='The date and time this data was last fetched.'), + ), + ] diff --git a/pydis_site/apps/home/models/repository_metadata.py b/pydis_site/apps/home/models/repository_metadata.py index 92d2404d..00a83cd7 100644 --- a/pydis_site/apps/home/models/repository_metadata.py +++ b/pydis_site/apps/home/models/repository_metadata.py @@ -1,32 +1,31 @@ from django.db import models -from django.utils import timezone class RepositoryMetadata(models.Model): """Information about one of our repos fetched from the GitHub API.""" last_updated = models.DateTimeField( - default=timezone.now, - help_text="The date and time this data was last fetched." + help_text="The date and time this data was last fetched.", + auto_now=True, ) repo_name = models.CharField( primary_key=True, max_length=40, - help_text="The full name of the repo, e.g. python-discord/site" + help_text="The full name of the repo, e.g. python-discord/site", ) description = models.CharField( max_length=400, - help_text="The description of the repo." + help_text="The description of the repo.", ) forks = models.IntegerField( - help_text="The number of forks of this repo" + help_text="The number of forks of this repo", ) stargazers = models.IntegerField( - help_text="The number of stargazers for this repo" + help_text="The number of stargazers for this repo", ) language = models.CharField( max_length=20, - help_text="The primary programming language used for this repo." + help_text="The primary programming language used for this repo.", ) def __str__(self): |