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"
|
||||
|
||||
|
||||
class AttributionAdminForm(forms.ModelForm):
|
||||
class AttributionTabularAdminForm(forms.ModelForm):
|
||||
listing = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['spectacle'].queryset = (
|
||||
Spectacle.objects
|
||||
.select_related('location')
|
||||
)
|
||||
spectacles = Spectacle.objects.select_related('location')
|
||||
if self.listing is not None:
|
||||
spectacles = spectacles.filter(listing=self.listing)
|
||||
self.fields['spectacle'].queryset = spectacles
|
||||
|
||||
|
||||
class AttributionNoListingAdminForm(AttributionAdminForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['spectacle'].queryset = (
|
||||
self.fields['spectacle'].queryset
|
||||
.filter(listing=False)
|
||||
)
|
||||
class WithoutListingAttributionTabularAdminForm(AttributionTabularAdminForm):
|
||||
listing = False
|
||||
|
||||
|
||||
class AttributionListingAdminForm(AttributionAdminForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['spectacle'].queryset = (
|
||||
self.fields['spectacle'].queryset
|
||||
.filter(listing=True)
|
||||
)
|
||||
class WithListingAttributionTabularAdminForm(AttributionTabularAdminForm):
|
||||
listing = True
|
||||
|
||||
|
||||
class AttributionInlineListing(admin.TabularInline):
|
||||
class AttributionInline(admin.TabularInline):
|
||||
model = Attribution
|
||||
extra = 0
|
||||
form = AttributionListingAdminForm
|
||||
listing = None
|
||||
|
||||
def get_queryset(self, 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):
|
||||
model = Attribution
|
||||
class WithListingAttributionInline(AttributionInline):
|
||||
form = WithListingAttributionTabularAdminForm
|
||||
listing = True
|
||||
|
||||
|
||||
class WithoutListingAttributionInline(AttributionInline):
|
||||
exclude = ('given', )
|
||||
extra = 0
|
||||
form = AttributionNoListingAdminForm
|
||||
|
||||
def get_queryset(self, request):
|
||||
qs = super().get_queryset(request)
|
||||
return qs.filter(spectacle__listing=False)
|
||||
form = WithoutListingAttributionTabularAdminForm
|
||||
listing = False
|
||||
|
||||
|
||||
class ParticipantAdminForm(forms.ModelForm):
|
||||
|
@ -91,7 +82,7 @@ class ParticipantAdminForm(forms.ModelForm):
|
|||
|
||||
|
||||
class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
||||
inlines = [AttributionInlineListing, AttributionInlineNoListing]
|
||||
inlines = [WithListingAttributionInline, WithoutListingAttributionInline]
|
||||
|
||||
def get_queryset(self, request):
|
||||
return Participant.objects.annotate(nb_places=Count('attributions'),
|
||||
|
|
Loading…
Reference in a new issue