Merge branch 'Aufinal/bda_admin_misc' into 'master'
Ergonomie de l'admin du BdA Closes #276 See merge request klub-dev-ens/gestioCOF!469
This commit is contained in:
commit
fb1a38cff3
3 changed files with 68 additions and 24 deletions
43
bda/admin.py
43
bda/admin.py
|
@ -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,14 @@ 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"
|
||||
)
|
||||
qset = Participant.objects.select_related("user", "tirage")
|
||||
|
||||
if self.instance.pk is not None:
|
||||
qset = qset.filter(tirage=self.instance.seller.tirage)
|
||||
|
||||
self.fields["confirmed_entry"].queryset = qset
|
||||
self.fields["seller"].queryset = qset
|
||||
self.fields["soldTo"].queryset = qset
|
||||
|
||||
|
||||
class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||
|
|
38
bda/migrations/0018_auto_20201021_1818.py
Normal file
38
bda/migrations/0018_auto_20201021_1818.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 2.2.12 on 2020-10-21 16:18
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bda", "0017_participant_accepte_charte"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="participant",
|
||||
options={"ordering": ("-tirage", "user__last_name", "user__first_name")},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="tirage",
|
||||
name="archived",
|
||||
field=models.BooleanField(default=False, verbose_name="Archivé"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="participant",
|
||||
name="tirage",
|
||||
field=models.ForeignKey(
|
||||
limit_choices_to={"archived": False},
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="bda.Tirage",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="participant",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("tirage", "user"), name="unique_tirage"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -31,6 +31,7 @@ class Tirage(models.Model):
|
|||
"Tirage à afficher dans le catalogue", default=False
|
||||
)
|
||||
enable_do_tirage = models.BooleanField("Le tirage peut être lancé", default=False)
|
||||
archived = models.BooleanField("Archivé", default=False)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s" % (
|
||||
|
@ -197,7 +198,9 @@ class Participant(models.Model):
|
|||
attributions = models.ManyToManyField(
|
||||
Spectacle, through="Attribution", related_name="attributed_to"
|
||||
)
|
||||
tirage = models.ForeignKey(Tirage, on_delete=models.CASCADE)
|
||||
tirage = models.ForeignKey(
|
||||
Tirage, on_delete=models.CASCADE, limit_choices_to={"archived": False}
|
||||
)
|
||||
accepte_charte = models.BooleanField("A accepté la charte BdA", default=False)
|
||||
choicesrevente = models.ManyToManyField(
|
||||
Spectacle, related_name="subscribed", blank=True
|
||||
|
@ -208,6 +211,12 @@ class Participant(models.Model):
|
|||
def __str__(self):
|
||||
return "%s - %s" % (self.user, self.tirage.title)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-tirage", "user__last_name", "user__first_name")
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=("tirage", "user"), name="unique_tirage"),
|
||||
]
|
||||
|
||||
|
||||
DOUBLE_CHOICES = (
|
||||
("1", "1 place"),
|
||||
|
|
Loading…
Reference in a new issue