forked from DGNum/gestioCOF
fix class name conflicts
This commit is contained in:
parent
0d8a613f28
commit
6cdb791989
1 changed files with 24 additions and 33 deletions
57
bda/admin.py
57
bda/admin.py
|
@ -29,55 +29,46 @@ class ChoixSpectacleInline(admin.TabularInline):
|
||||||
sortable_field_name = "priority"
|
sortable_field_name = "priority"
|
||||||
|
|
||||||
|
|
||||||
class AttributionAdminForm(forms.ModelForm):
|
class AttributionTabularAdminForm(forms.ModelForm):
|
||||||
|
listing = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['spectacle'].queryset = (
|
spectacles = Spectacle.objects.select_related('location')
|
||||||
Spectacle.objects
|
if self.listing is not None:
|
||||||
.select_related('location')
|
spectacles = spectacles.filter(listing=self.listing)
|
||||||
)
|
self.fields['spectacle'].queryset = spectacles
|
||||||
|
|
||||||
|
|
||||||
class AttributionNoListingAdminForm(AttributionAdminForm):
|
class WithoutListingAttributionTabularAdminForm(AttributionTabularAdminForm):
|
||||||
|
listing = False
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.fields['spectacle'].queryset = (
|
|
||||||
self.fields['spectacle'].queryset
|
|
||||||
.filter(listing=False)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AttributionListingAdminForm(AttributionAdminForm):
|
class WithListingAttributionTabularAdminForm(AttributionTabularAdminForm):
|
||||||
|
listing = True
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.fields['spectacle'].queryset = (
|
|
||||||
self.fields['spectacle'].queryset
|
|
||||||
.filter(listing=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AttributionInlineListing(admin.TabularInline):
|
class AttributionInline(admin.TabularInline):
|
||||||
model = Attribution
|
model = Attribution
|
||||||
extra = 0
|
extra = 0
|
||||||
form = AttributionListingAdminForm
|
listing = None
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
qs = super().get_queryset(request)
|
qs = super().get_queryset(request)
|
||||||
return qs.filter(spectacle__listing=True)
|
if self.listing is not None:
|
||||||
|
qs.filter(spectacle__listing=self.listing)
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class AttributionInlineNoListing(admin.TabularInline):
|
class WithListingAttributionInline(AttributionInline):
|
||||||
model = Attribution
|
form = WithListingAttributionTabularAdminForm
|
||||||
|
listing = True
|
||||||
|
|
||||||
|
|
||||||
|
class WithoutListingAttributionInline(AttributionInline):
|
||||||
exclude = ('given', )
|
exclude = ('given', )
|
||||||
extra = 0
|
form = WithoutListingAttributionTabularAdminForm
|
||||||
form = AttributionNoListingAdminForm
|
listing = False
|
||||||
|
|
||||||
def get_queryset(self, request):
|
|
||||||
qs = super().get_queryset(request)
|
|
||||||
return qs.filter(spectacle__listing=False)
|
|
||||||
|
|
||||||
|
|
||||||
class ParticipantAdminForm(forms.ModelForm):
|
class ParticipantAdminForm(forms.ModelForm):
|
||||||
|
@ -91,7 +82,7 @@ class ParticipantAdminForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
||||||
inlines = [AttributionInlineListing, AttributionInlineNoListing]
|
inlines = [WithListingAttributionInline, WithoutListingAttributionInline]
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return Participant.objects.annotate(nb_places=Count('attributions'),
|
return Participant.objects.annotate(nb_places=Count('attributions'),
|
||||||
|
|
Loading…
Reference in a new issue