update ordering, queryset
This commit is contained in:
@@ -2,7 +2,6 @@ from django.contrib import admin, messages
|
||||
from django.utils.html import format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ngettext
|
||||
|
||||
from segno import helpers
|
||||
|
||||
from .forms import (
|
||||
@@ -336,6 +335,8 @@ class WirefAdmin(admin.ModelAdmin):
|
||||
"total",
|
||||
]
|
||||
|
||||
ordering = ["-wiref_id"]
|
||||
|
||||
def add_view(self, request, form_url="", extra_context=None):
|
||||
extra_context = extra_context or {}
|
||||
extra_context["help_text"] = "Fette Schriften sind Pflichtfelder."
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.core.validators import ValidationError
|
||||
from django.db.models import Count
|
||||
from django.forms import DateInput
|
||||
|
||||
from members.models import Member
|
||||
@@ -312,6 +313,18 @@ class BillAdminForm(forms.ModelForm):
|
||||
self.fields["bill_creator"].widget.can_change_related = False
|
||||
self.fields["bill_creator"].widget.can_delete_related = False
|
||||
|
||||
# delete wiref id from list if there are already 8 bills in wiref form.
|
||||
qs = (
|
||||
self.fields["wiref"]
|
||||
.queryset.annotate(num_bills=Count("bill"))
|
||||
.filter(num_bills__lt=8)
|
||||
)
|
||||
|
||||
# delete wiref id from if there is a uploaded wiref file.
|
||||
qs = qs.filter(file_field="")
|
||||
|
||||
self.fields["wiref"].queryset = qs.order_by("-wiref_id")
|
||||
|
||||
|
||||
class ResolutionAdminForm(forms.ModelForm):
|
||||
total = forms.CharField()
|
||||
@@ -373,8 +386,10 @@ class WirefAdminForm(forms.ModelForm):
|
||||
super().__init__(*args, **kwargs) # to get the self.fields set
|
||||
|
||||
wiref = kwargs.get("instance", None)
|
||||
bills = Bill.objects.filter(wiref=wiref)
|
||||
total = 0
|
||||
|
||||
if wiref is not None:
|
||||
bills = Bill.objects.filter(wiref=wiref)
|
||||
for elem in bills:
|
||||
total += elem.amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user