From bff0d5f1e6015ae062a744548472c89c32744c8d Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Tue, 28 May 2024 13:16:28 +0200 Subject: [PATCH] Do not modify Download objects --- app/grandchallenge/serving/admin.py | 6 ++---- ...d_unique_together_remove_download_count.py | 21 +++++++++++++++++++ app/grandchallenge/serving/models.py | 5 ----- app/grandchallenge/serving/views.py | 6 +----- 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 app/grandchallenge/serving/migrations/0003_alter_download_unique_together_remove_download_count.py diff --git a/app/grandchallenge/serving/admin.py b/app/grandchallenge/serving/admin.py index 17308dc562..748093b008 100644 --- a/app/grandchallenge/serving/admin.py +++ b/app/grandchallenge/serving/admin.py @@ -5,10 +5,9 @@ @admin.register(Download) class DownloadAdmin(admin.ModelAdmin): - ordering = ("-modified",) + ordering = ("-created",) list_display = ( - "modified", - "count", + "created", "creator", "image", "submission", @@ -25,7 +24,6 @@ class DownloadAdmin(admin.ModelAdmin): "feedback__pk", ) readonly_fields = ( - "count", "creator", "image", "submission", diff --git a/app/grandchallenge/serving/migrations/0003_alter_download_unique_together_remove_download_count.py b/app/grandchallenge/serving/migrations/0003_alter_download_unique_together_remove_download_count.py new file mode 100644 index 0000000000..43f3661a32 --- /dev/null +++ b/app/grandchallenge/serving/migrations/0003_alter_download_unique_together_remove_download_count.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.13 on 2024-05-28 11:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("serving", "0002_download_challenge_request_and_more"), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="download", + unique_together=set(), + ), + migrations.RemoveField( + model_name="download", + name="count", + ), + ] diff --git a/app/grandchallenge/serving/models.py b/app/grandchallenge/serving/models.py index 6b37ba3085..6d445dbad9 100644 --- a/app/grandchallenge/serving/models.py +++ b/app/grandchallenge/serving/models.py @@ -36,8 +36,3 @@ class Download(models.Model): feedback = models.ForeignKey( Feedback, null=True, on_delete=models.CASCADE, editable=False ) - - count = models.BigIntegerField(default=1, editable=False) - - class Meta: - unique_together = ("creator", "image", "submission") diff --git a/app/grandchallenge/serving/views.py b/app/grandchallenge/serving/views.py index 6c1e576a28..71f50350ae 100644 --- a/app/grandchallenge/serving/views.py +++ b/app/grandchallenge/serving/views.py @@ -2,7 +2,6 @@ from django.conf import settings from django.core.exceptions import MultipleObjectsReturned, PermissionDenied -from django.db.models import F from django.http import Http404, HttpResponseRedirect from django.utils._os import safe_join from guardian.utils import get_anonymous_user @@ -72,10 +71,7 @@ def _create_download( "creator and only one other foreign key must be set" ) - n_updated = Download.objects.filter(**kwargs).update(count=F("count") + 1) - - if n_updated == 0: - Download.objects.create(**kwargs) + Download.objects.create(**kwargs) def serve_images(request, *, pk, path, pa="", pb=""):