add status to wiref

This commit is contained in:
2024-01-10 10:24:48 +00:00
parent d54a632d67
commit 45279aac8d
3 changed files with 30 additions and 0 deletions

View File

@@ -331,10 +331,12 @@ class WirefAdmin(admin.ModelAdmin):
list_display = [
"wiref_id",
"status",
"file_field",
"total",
]
actions = ["make_cleared", "make_finished"]
ordering = ["-wiref_id"]
def add_view(self, request, form_url="", extra_context=None):
@@ -364,3 +366,17 @@ class WirefAdmin(admin.ModelAdmin):
total += elem.amount
return f"{ total }"
@admin.action(description="Als 'Abgeschlossen' markieren.")
def make_finished(self, request, queryset):
updated = queryset.update(status=Wiref.Status.CLOSED)
self.message_user(
request,
ngettext(
"%d Wiref Formular wurde als 'Abgeschlossen' markiert.",
"%d Wiref Formulare wurden als 'Abgeschlossen' markiert.",
updated,
)
% updated,
messages.SUCCESS,
)

View File

@@ -373,6 +373,7 @@ class WirefAdminForm(forms.ModelForm):
fields = [
"wiref_id",
"status",
"file_field",
"total",
]
@@ -385,6 +386,8 @@ class WirefAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # to get the self.fields set
self.fields["wiref_id"].required = True
wiref = kwargs.get("instance", None)
total = 0

View File

@@ -91,6 +91,17 @@ class Wiref(models.Model):
verbose_name="Wiref Formular",
)
class Status(models.TextChoices):
OPENED = "O", "Offen"
CLOSED = "C", "Abgeschlossen"
status = models.CharField(
max_length=1,
choices=Status.choices,
default=Status.OPENED,
verbose_name="Status",
)
class Meta:
verbose_name = "Wiref Formular"
verbose_name_plural = "Wiref Formulare"