Skip to content

Commit

Permalink
ADSForm: dynamically set the field epci_commune
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Mar 29, 2024
1 parent 8d6c382 commit fde5e64
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions mesads/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ADSForm(forms.ModelForm):
class Meta:
model = ADS
fields = (
"epci_commune",
"number",
"ads_creation_date",
"ads_in_use",
Expand All @@ -109,7 +108,16 @@ class Meta:

def __init__(self, epci=None, *args, **kwargs):
super().__init__(*args, **kwargs)

if epci:
self.Meta.fields = self.Meta.fields + ("epci_commune",)
self.fields["epci_commune"] = forms.ModelChoiceField(
queryset=None,
widget=autocomplete.ListSelect2(),
label=ADS.epci_commune.field.verbose_name,
help_text=ADS.epci_commune.field.help_text,
required=False,
)
self.fields["epci_commune"].queryset = Commune.objects.filter(
departement=epci.departement
)
Expand All @@ -124,14 +132,6 @@ def save(self, check=True):
self._save_m2m()
return self.instance

epci_commune = forms.ModelChoiceField(
queryset=None,
widget=autocomplete.ListSelect2(),
label=ADS.epci_commune.field.verbose_name,
help_text=ADS.epci_commune.field.help_text,
required=False,
)

ads_in_use = NullBooleanField(
widget=BooleanSelect(),
label=ADS.ads_in_use.field.verbose_name,
Expand Down

0 comments on commit fde5e64

Please sign in to comment.