def kv_create(request, kv_class, obj_pk):
    """
    POST to:
    /core/keyvalue/api/<kv_class>/create/

    with parameters like:

    {
        'key': 'key_string'
        'value': 'value_string'
        'obj_pk': 1
    }

    Status Codes:
        * 201 - Object created
        * 400 - Issues during creation
    """
    key, value, errors = get_kv(request)
    if errors:
        return HttpResponse(
            status=400, content=json.dumps(
                {'success': False, 'message': errors}
            )
        )
    obj, KVKlass = resolve_obj(kv_class, obj_pk)
    try:
        kv = KVKlass(obj=obj, key=key, value=value)
        kv.clean()
        kv.save()
        resp = {
            'status': 201,
            'content': json.dumps(
                {
                    'success': True,
                    'key': kv.key,
                    'value': kv.value,
                    'obj_uri': kv.uri,
                    'kv_pk': kv.pk
                }
            )
        }
    except __HOLE__, e:
        resp = {
            'status': 400,
            'content': json.dumps({'success': False, 'message': str(e)})
        }
    return HttpResponse(**resp)
dataset/ETHPy150Open mozilla/inventory/core/keyvalue/api.py/kv_create