Limite les select au tirage concerné

This commit is contained in:
Ludovic Stephan 2020-10-21 18:22:48 +02:00
parent d535cf24a3
commit 147b8514ef

View file

@ -94,9 +94,12 @@ class WithoutListingAttributionInline(AttributionInline):
class ParticipantAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["choicesrevente"].queryset = Spectacle.objects.select_related(
"location"
)
queryset = Spectacle.objects.select_related("location")
if self.instance.pk is not None:
queryset = queryset.filter(tirage=self.instance.tirage)
self.fields["choicesrevente"].queryset = queryset
class ParticipantPaidFilter(admin.SimpleListFilter):
@ -202,17 +205,6 @@ class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
class AttributionAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if "spectacle" in self.fields:
self.fields["spectacle"].queryset = Spectacle.objects.select_related(
"location"
)
if "participant" in self.fields:
self.fields["participant"].queryset = Participant.objects.select_related(
"user", "tirage"
)
def clean(self):
cleaned_data = super().clean()
participant = cleaned_data.get("participant")
@ -225,6 +217,12 @@ class AttributionAdminForm(forms.ModelForm):
)
return cleaned_data
class Meta:
widgets = {
"participant": ModelSelect2(url="bda-participant-autocomplete"),
"spectacle": ModelSelect2(url="bda-spectacle-autocomplete"),
}
class AttributionAdmin(ReadOnlyMixin, admin.ModelAdmin):
@ -284,15 +282,20 @@ class SalleAdmin(admin.ModelAdmin):
class SpectacleReventeAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["confirmed_entry"].queryset = Participant.objects.select_related(
"user", "tirage"
)
self.fields["seller"].queryset = Participant.objects.select_related(
"user", "tirage"
)
self.fields["soldTo"].queryset = Participant.objects.select_related(
"user", "tirage"
confirmed_entry_qset = Participant.objects.select_related("user", "tirage")
seller_qset = Participant.objects.select_related("user", "tirage")
soldTo_qset = Participant.objects.select_related("user", "tirage")
if self.instance.pk is not None:
confirmed_entry_qset = confirmed_entry_qset.filter(
tirage=self.instance.seller.tirage
)
seller_qset = seller_qset.filter(tirage=self.instance.seller.tirage)
soldTo_qset = soldTo_qset.filter(tirage=self.instance.seller.tirage)
self.fields["confirmed_entry"].queryset = confirmed_entry_qset
self.fields["seller"].queryset = seller_qset
self.fields["soldTo"].queryset = soldTo_qset
class SpectacleReventeAdmin(admin.ModelAdmin):