From 7a682ed6d0ff9a716a5489d06d6f326101804451 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Tue, 31 Oct 2023 09:31:28 +1100 Subject: [PATCH] usethesource: Add "ordering" field to determine candidate sort order --- conservancy/usethesource/admin.py | 3 ++- .../migrations/0002_auto_20231030_1830.py | 22 +++++++++++++++++++ conservancy/usethesource/models.py | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 conservancy/usethesource/migrations/0002_auto_20231030_1830.py diff --git a/conservancy/usethesource/admin.py b/conservancy/usethesource/admin.py index ae5df7f3..bb82aa25 100644 --- a/conservancy/usethesource/admin.py +++ b/conservancy/usethesource/admin.py @@ -11,7 +11,8 @@ class CommentInline(admin.TabularInline): @admin.register(Candidate) class CandidateAdmin(admin.ModelAdmin): - list_display = ['name', 'vendor', 'device', 'release_date'] + list_display = ['name', 'vendor', 'device', 'release_date', 'ordering'] + list_editable = ['ordering'] fields = [ 'name', 'slug', diff --git a/conservancy/usethesource/migrations/0002_auto_20231030_1830.py b/conservancy/usethesource/migrations/0002_auto_20231030_1830.py new file mode 100644 index 00000000..755a650d --- /dev/null +++ b/conservancy/usethesource/migrations/0002_auto_20231030_1830.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.19 on 2023-10-30 18:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('usethesource', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='candidate', + options={'ordering': ['ordering', 'name']}, + ), + migrations.AddField( + model_name='candidate', + name='ordering', + field=models.SmallIntegerField(default=0), + ), + ] diff --git a/conservancy/usethesource/models.py b/conservancy/usethesource/models.py index 743efd6a..08d09699 100644 --- a/conservancy/usethesource/models.py +++ b/conservancy/usethesource/models.py @@ -11,6 +11,10 @@ class Candidate(models.Model): description = models.TextField() source_url = models.URLField() binary_url = models.URLField(blank=True) + ordering = models.SmallIntegerField(default=0) + + class Meta: + ordering = ['ordering', 'name'] def __str__(self): return self.name