def getMaxAffiliationInstanceID ( ) : dbconnectionhanlder = DBConnection ( ) dbconnectionhanlder . cursor . execute ( "SELECT max(id) from `django-tethne_affiliation_instance`" ) rows = dbconnectionhanlder . cursor . fetchall ( ) dbconnectionhanlder . conn . close ( ) if rows [ 0 ] [ 0 ] is None : return 0 else : return rows [ 0 ] [ 0 ]
python django how to get largest id
def getMaxAffiliationInstanceID():
    """

    Returns
    -------
    maximum value of the Primary key from the table "django-tethne_affiliation_instance"
    This is used to calculate the next id for primary key.

    if the table is empty, 0 is returned

    """
    dbconnectionhanlder = DBConnection()
    dbconnectionhanlder.cursor.execute("SELECT max(id) from `django-tethne_affiliation_instance`")
    rows = dbconnectionhanlder.cursor.fetchall()
    dbconnectionhanlder.conn.close()
    if rows[0][0] is None:
        return 0
    else:
        return rows[0][0]