title: How to write the django-piston handler to create and return ApiKey?
body: <p>I'm currently working on the project that use Android for client and Django for web server. I decided to use piston-django to create REST API authentication and I've follow this instruction:
  <a href="https://stackoverflow.com/questions/4457876/what-is-the-right-way-to-write-a-django-piston-client/">What is the right way to write a django-piston client?</a>
  and write my own handler (api/handlers.py) to create and return ApiKey like this:</p>
  
  <pre><code>class ApiKeyhandler(Basehandler):
      model = ApiKey
      allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
      fields = ('user', 'keys')
  
      def create(self, request):
          attrs = self.flatten_dict(request.POST)
  
          if self.exists(**attrs):
              return rc.DUPLICATE_ENTRY
          else:
              apikey = ApiKey(user=request.user)
              apikey.save()
  
              return apikey
  </code></pre>
  
  <p>and in urls.py I use HttpBasicAuthentication for this handler:</p>
  
  <pre><code> auth = HttpBasicAuthentication(realm="Authentication API")
   apikey = Resource(handler=ApiKeyHandler, authentication=auth)
  </code></pre>
  
  <p>but when I test it with <a href="http://hurl.it" rel="nofollow noreferrer">http://hurl.it</a></p>
  
  <p><a href="http://hurl.it/hurls/40f437de087c2b109a709b53a20b8b2d735c1c01/c807f01a3a03623563242ecbf822e530c603f2d5" rel="nofollow noreferrer">This is the response from GET</a></p>
  
  <p><a href="http://hurl.it/hurls/b87435ab82ac5d3c215f102926037a1c7da6a969/0dea84f2841d2e3579b6bebefcf0c6bfa70fb436" rel="nofollow noreferrer">This is the response from POST method</a></p>
  
  <p>Can anyone tell me how to write the complete code for this question or any suggestion on this problem?</p>