def primary_key(cls):
    keys = class_keys(cls)

    if len(keys) > 1:
        # guess the pk
        pk = cls.__name__.lower() + '_id'
    else:
        pk = next(iter(keys), None)

    if pk not in cls.__dict__:
        # could not find pk field in class, now check
        # whether it has been explicitly specified
        if 'pk_field' in cls.__dict__:
            pk = cls.__dict__['pk_field']
        else:
            raise KeyNotFoundException("Could not figure out primary key field"
                                       "for %s model. Tried to first use %s as"
                                       " field name,and then looked for"
                                       " pk_field attr which was also missing"
                                       % (cls.__name__, pk))

    return pk
Utility function to get the primary key
dataset/ETHPy150Open dealertrack/djangorest-alchemy/djangorest_alchemy/inspector.py/primary_key