Skip to content

Instantly share code, notes, and snippets.

@kriwil
Created August 29, 2014 09:20
Show Gist options
  • Save kriwil/95239e1a3521fc52b1cd to your computer and use it in GitHub Desktop.
Save kriwil/95239e1a3521fc52b1cd to your computer and use it in GitHub Desktop.
class AccountForm(forms.ModelForm):
class Meta:
model = Account
fields = ['first_name', 'last_name', 'email', 'password']
def __init__(self, *args, **kwargs):
self.university = kwargs.pop('university')
self.high_school = kwargs.pop('high_school')
self.department = kwargs.pop('department')
def save(self, *args, **kwargs):
data = self.cleaned_data
kwargs['commit'] = False
instance = super(AccountForm, self).save(*args, **kwargs)
instance.university = self.university
instance.high_school = self.high_school
class AccountCreate(generic.CreateView):
form_class = AccountForm
model = Account
template_name = "account/update.html"
def get_success_url(self):
return reverse('account:index')
def get_context_data(self, **kwargs):
context = super(AccountCreate, self).get_context_data(**kwargs)
context['action'] = reverse('account:create')
return context
def get_form_kwargs(self, **kwargs):
form_kwargs = super(AccountCreate, self).get_form_kwargs(**kwargs)
form_kwargs['university'] = self.request.POST['univ_cmb_box']
form_kwargs['department'] = self.request.POST['department_cmb_box']
form_kwargs['high_school'] = self.request.POST['hs_cmb_box']
return form_kwargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment