def get_new_pid(institute):
    """ Return a new Project ID
    Keyword arguments:
    institute_id -- Institute id
    """
    number = '0001'
    prefix = 'p%s' % institute.name.replace(' ', '')[:4]

    found = True
    while found:
        try:
            Project.objects.get(pid=prefix + number)
            number = str(int(number) + 1)
            if len(number) == 1:
                number = '000' + number
            elif len(number) == 2:
                number = '00' + number
            elif len(number) == 3:
                number = '0' + number
        except Project.DoesNotExist:
            found = False

    return prefix + number
def get_new_pid ( institute ) : number = '0001' prefix = 'p%s' % institute . name . replace ( ' ' , '' ) [ : 4 ] found = True while found : try : Project . objects . get ( pid = prefix + number ) number = str ( int ( number ) + 1 ) if len ( number ) == 1 : number = '000' + number elif len ( number ) == 2 : number = '00' + number elif len ( number ) == 3 : number = '0' + number except Project . DoesNotExist : found = False return prefix + number
Return a new Project ID
    Keyword arguments:
    institute_id -- Institute id