Improve taskresults app

- show created/modified fields in admin
- add verbose output to management command
- add date hierarchy and action filters in admin
This commit is contained in:
Jan Dittberner 2023-04-29 11:10:23 +02:00
parent 397e479925
commit 2d05580ed3
4 changed files with 33 additions and 6 deletions

View file

@ -11,5 +11,10 @@ from .models import TaskResult
@admin.register(TaskResult)
class TaskResultAdmin(admin.ModelAdmin):
list_display = ('task_id', 'creator', 'signature', 'finished', 'state')
list_filter = ('finished',)
list_display = ("task_id", "creator", "signature", "finished", "state")
list_filter = ("finished", "creator")
date_hierarchy = "created"
readonly_fields = ("created", "modified")
def has_add_permission(self, request):
return False

View file

@ -13,6 +13,10 @@ class Command(BaseCommand):
help = "fetch task results"
def handle(self, *args, **options):
for taskresult in TaskResult.objects.filter(finished=False):
taskresult.fetch_result()
taskresult.save()
for task_result in TaskResult.objects.filter(finished=False):
if options["verbosity"] > 1:
print(f"fetching result for unfinished task {task_result.task_id}", file=self.stderr)
task_result.fetch_result()
if options["verbosity"] > 2:
print(f"fetched result for unfinished task {task_result.task_id}", file=self.stderr)
task_result.save()

View file

@ -0,0 +1,17 @@
# Generated by Django 3.2.18 on 2023-04-29 08:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('taskresults', '0003_auto_20160109_1524'),
]
operations = [
migrations.AlterModelOptions(
name='taskresult',
options={'ordering': ['-modified'], 'verbose_name': 'Task result', 'verbose_name_plural': 'Task results'},
),
]

View file

@ -3,6 +3,7 @@ This model defines the database models to handle Celery AsyncResults.
"""
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext as _
from model_utils.models import TimeStampedModel
@ -33,7 +34,7 @@ class TaskResult(TimeStampedModel):
class Meta:
verbose_name = _("Task result")
verbose_name_plural = _("Task results")
ordering = ["created"]
ordering = ["-modified"]
def __str__(self):
return "{creator} ({task_id}): {finished}".format(