summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/forms_common.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 0a001883c..661709a09 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -139,6 +139,14 @@ class PersonForm(forms.Form):
reverse_lazy('autocomplete-organization'),
associated_model=models.Organization, new=True),
validators=[models.valid_id(models.Organization)], required=False)
+ person_types = forms.MultipleChoiceField(label=_("Person type"),
+ choices=[], widget=forms.CheckboxSelectMultiple)
+
+ def __init__(self, *args, **kwargs):
+ super(PersonForm, self).__init__(*args, **kwargs)
+ self.fields['person_types'].choices = models.PersonType.get_types(
+ empty_first=False)
+ self.fields['person_types'].help_text = models.PersonType.get_help()
def save(self, user):
dct = self.cleaned_data
@@ -146,8 +154,10 @@ class PersonForm(forms.Form):
if 'attached_to' in dct and dct['attached_to']:
dct['attached_to'] = models.Organization.objects.get(
pk=dct['attached_to'])
- new_item = models.Person(**dct)
- new_item.save()
+ person_types = dct.pop('person_types')
+ new_item = models.Person.objects.create(**dct)
+ for pt in person_types:
+ new_item.person_types.add(pt)
return new_item
class PersonTypeForm(forms.Form):