diff options
author | MR Lemon <matt@matthewlemon> | 2020-04-20 16:39:16 +0100 |
---|---|---|
committer | MR Lemon <matt@matthewlemon> | 2020-04-20 16:39:16 +0100 |
commit | 6c06361481ae9565b3da523b360c480ead48c47e (patch) | |
tree | accea8eac4fbad4ba37b26e776ccd48c2baa33bb /ctrack/caf/forms.py | |
parent | 324f91f31141fd35ad108142922956893dc4fd3e (diff) |
Completed a manual forms.Form to create a new ApplicableSystem - REFERENCE CODE
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/forms.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index e9eef3b..f470dae 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -10,26 +10,24 @@ from django.urls import reverse from ctrack.caf.models import ApplicableSystem from ctrack.caf.models import CAF +from ctrack.organisations.models import Organisation CAFCreateInlineFormset = inlineformset_factory( CAF, ApplicableSystem, fields=("name", "organisation"), extra=2) class ApplicableSystemCreateFromOrgForm(forms.Form): - choices = () name = forms.CharField(max_length=255) description = forms.CharField(widget=forms.Textarea) - organisation = forms.ModelChoiceField(queryset=None) - caf = forms.ChoiceField(choices=( - choices - )) + organisation = forms.ModelChoiceField(queryset=Organisation.objects.all()) + caf = forms.ModelChoiceField(queryset=CAF.objects.all()) def __init__(self, org_id, slug, org_name, org_cafs, *args, **kwargs): super().__init__(*args, **kwargs) cancel_redirect = reverse("organisations:detail", args=[slug]) - ApplicableSystemCreateFromOrgForm.choices = org_cafs + # we need to create the choices we can use for the CAF dropdown in the form + self.fields['caf'].queryset = CAF.objects.filter(pk__in=[caf.pk for caf in org_cafs]) self.helper = FormHelper(self) - self.helper.form_method = "post" self.helper.layout = Layout( Fieldset( f"Create a new system for {org_name}", |