Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to properly extract selected object id from a table

I have a custom panel, which contains a data table along with a few action links. When a single table row is selected, and an action button is clicked, I need to be able to get the object id of the selected row object. Currently, I'm doing it this way:

class SimpleAssociateIP(tables.Action):

def single(self, table, request, instance_id):

    r = request
    post = str(r.POST)
    post = post.replace("<", "{").replace(">", "}")\
        .replace("'", "\"").replace("u", "").replace("{QeryDict: ", "")\
        .replace("}}", "}")
    post_json = json.loads(post)
    print "POST:   "
    raw_id = str(post_json["object_ids"])
    id = raw_id.replace("[u'", "").replace("']", "")
    print id

This works, but I have a feeling, that there is a better way. Does anyone knows a better way to get to such object id?

-Eugene

how to properly extract selected object id from a table

I have a custom panel, which contains a data table along with a few action links. When a single table row is selected, and an action button is clicked, I need to be able to get the object id of the selected row object. Currently, I'm doing it this way:

class SimpleAssociateIP(tables.Action):

def single(self, table, request, instance_id):

    r = request
    post = str(r.POST)
    post = post.replace("<", "{").replace(">", "}")\
        .replace("'", "\"").replace("u", "").replace("{QeryDict: ", "")\
        .replace("}}", "}")
    post_json = json.loads(post)
    print "POST:   "
    raw_id = str(post_json["object_ids"])
    id = raw_id.replace("[u'", "").replace("']", "")
    print id

This works, but I have a feeling, that there is a better way. Does anyone knows a better way to get to such object id?

-Eugene