jbrendel/django-randomprimary

Add blank=true

Opened this issue · 0 comments

Hello and thanks for your awesome model. The only issue I found after a considerable amount of debugging was that it behaves slightly differently to an AutoField: AutoFields appear to have blank=True by default, so that they (correctly) are not required to be set in forms. RandomPrimaryIdModel has blank=False, which generates an "xxx is required" error on form submission and prevents automatic key generation. I would suggest changing this section

    id = models.CharField(db_index    = True,
                          primary_key = True,
                          max_length  = CRYPT_KEY_LEN_MAX+1+len(KEYPREFIX)+len(KEYSUFFIX),
                          unique      = True)

to

    id = models.CharField(db_index    = True,
                          primary_key = True,
                          max_length  = CRYPT_KEY_LEN_MAX+1+len(KEYPREFIX)+len(KEYSUFFIX),
                          unique      = True,
                          blank       = True)

This fixed the problem for me. Otherwise it works very smoothly and as expected!