title: Django class-based UpdateView
body: <p>We are using Django 1.9.5. I am writing update company profile view. I want to have two fields on my update profile page: </p>
  
  <ul>
  <li>company <code>name</code>,</li>
  <li><code>apikey</code>(generated with a dedicated function).</li>
  </ul>
  
  <p>I want to change field <code>name</code> by hands and then save by clicking button Update. For filed <code>apikey</code> I want to have separated button which would automatically generate new key, save it to db and update my page.</p>
  
  <p>I am overwriting <code>post</code> method at <code>UpdateView</code> class. But simething isn't working. Please take a look at my code:</p>
  
  <p><code>models.py:</code></p>
  
  <pre><code>class Organization(models.Model):
  
      name = models.CharField(_('organisation display name'), max_length=512,
                              blank=True)
  
  
      apikey = models.CharField(_("API authentication key"), max_length=APIKEY_LENGTH,
                                default=get_apikey)
  </code></pre>
  
  <p>where <code>get_apikey</code> is </p>
  
  <pre><code>from django.utils.crypto import get_random_string
  
  
  APIKEY_PREFIX = "key-"
  APIKEY_LENGTH = 80
  
  
  def get_apikey():
      rnd_len = APIKEY_LENGTH - len(APIKEY_PREFIX)
      return "{}{}".format(
              APIKEY_PREFIX,
              get_random_string(rnd_len, "abcdefghijklmnopqrstuvwxyz0123456789")
      )
  </code></pre>
  
  <p><code>forms.py:</code></p>
  
  <pre><code>from django import forms
  from crispy_forms.helper import FormHelper, Layout
  from orgs.models import Organization
  
  
  class OrgProfileForm(forms.ModelForm):
      def __init__(self, *args, **kwargs):
          super(OrgProfileForm, self).__init__(*args, **kwargs)
          self.helper = FormHelper()
          self.helper.form_tag = False
  
      class Meta:
          model = Organization
          fields = ['name', 'apikey']
  </code></pre>
  
  <p><code>views.py</code></p>
  
  <pre><code>from django.views.generic.edit import UpdateView, BaseUpdateView
  from orgs.forms import OrgProfileForm
  from orgs.models import Organization
  from local.auth import get_apikey
  
  
  class OrgProfileView(UpdateView):
      model = Organization
      template_name = 'orgs/orgprofile.html'
      form_class = OrgProfileForm
      url_name = 'profile'
      success_url = '/'
  
      def get_object(self, queryset=None):
          org_obj = Organization.objects.get(orgname=self.kwargs["orgname"])
          return org_obj
  
      def post(self, request, *args, **kwargs):
          import ipdb
          ipdb.set_trace()
          if '_key' in request.POST:
              org_obj = Organization.objects.get(orgname=self.kwargs["orgname"])
              org_obj.apikey = get_apikey()
              org_obj.save()
          self.object = org_obj
          return super(BaseUpdateView, self).post(request, *args, **kwargs)
  </code></pre>
  
  <p><code>template.html</code></p>
  
  <pre><code>{% extends "base.html" %}
  {% load i18n %}
  {% load staticfiles %}
  {% load crispy_forms_tags %}
  
  {% block title %}{% trans "Organization profile" %}{% endblock title %}
  {% block header_title %}{% trans "Organization profile" %}{% endblock header_title %}
  
  
  {% block content %}
      &lt;form action="" method="post"&gt;{% csrf_token %}
          {% crispy form %}
          &lt;input type="submit" value="{% trans 'Generate new key' %}" name="_key"&gt;
          &lt;input type="submit" value="{% trans 'Update form' %}" name="_update"&gt;
      &lt;/form&gt;
  {% endblock content %}
  </code></pre>
  
  <p>Using <code>_key</code> and '_update' I want to differentiate between two buttons and actions update <code>name</code> and regenerate new <code>apikey</code>.</p>