1 from django import forms
2 from .models import Organization, UserCard, countries
4 class OrganizationForm(forms.ModelForm):
11 class UserCardForm(forms.ModelForm):
14 first_name = forms.CharField(required=False)
15 last_name = forms.CharField(required=False)
19 exclude = ['_html', 'user']
21 def __init__(self, *args, **kwargs):
22 if 'instance' in kwargs:
24 'first_name': kwargs['instance'].user.first_name,
25 'last_name': kwargs['instance'].user.last_name,
27 return super(UserCardForm, self).__init__(*args, **kwargs)
29 def save(self, *args, **kwargs):
30 self.instance.user.first_name = self.cleaned_data.get('first_name', '')
31 self.instance.user.last_name = self.cleaned_data.get('last_name', '')
32 self.instance.user.save()
33 return super(UserCardForm, self).save(*args, **kwargs)