Skip to content

Commit

Permalink
feat(admin): Limit active job options to successful jobs. Order licen…
Browse files Browse the repository at this point in the history
…ses by name.
  • Loading branch information
jpmckinney committed Nov 8, 2024
1 parent 4ddeb14 commit 25b178d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions data_registry/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.contrib.admin import widgets
from django.db.models import F

from data_registry import models
from data_registry.util import scrapyd_url

FLAGS_DIR = Path("data_registry/static/img/flags")
Expand Down Expand Up @@ -71,9 +70,11 @@ def __init__(self, *args, request=None, **kwargs):
# It's not obvious how to use limit_choices_to to filter jobs by collection.
# https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to
self.fields["active_job"].queryset = (
models.Job.objects.filter(collection=self.instance).complete().order_by(F("pk").desc())
self.fields["active_job"].queryset.filter(collection=self.instance).successful().order_by(F("pk").desc())
)

self.fields["license_custom"].queryset = self.fields["license_custom"].queryset.order_by("name")

# Populate choices in the form, not the model, for easier migration between icon sets.
self.fields["country_flag"].choices += sorted((f.name, f.name) for f in FLAGS_DIR.iterdir() if f.is_file())

Expand Down

0 comments on commit 25b178d

Please sign in to comment.