[Answer]-Handle data from added field in ModelForm via Create View

1👍

You can do this in the form_valid() method of the CreateView.

class Registration(CreateView):
    """
    View handles user registration.
    """
    form_class = ExampleForm
    model = Example
    template_name = 'accounts/registration.html'
    success_url = reverse_lazy('accounts:registered')

    def form_valid(self, form):
        example = form.save(commit=False)
        example.extra_field = derive_data(form.cleaned_data)
        example.save()
        return super(Registration, self).form_valid(form)

Leave a comment