I am updating a django app from 1.4 to 1.8 and have hit a small problem with django admin.
My models look like this
def new_key():
return binascii.b2a_hex(os.urandom(20))
class ApiKey(models.Model):
customer = models.ForeignKey(UserProfile)
key = models.CharField(max_length=40, default=new_key)
And admin.py is
class ApiKeyInline(admin.StackedInline):
model = ApiKey
extra = 0
class UserProfileAdmin(admin.ModelAdmin):
inlines = [ApiKeyInline]
admin.site.register(UserProfile, UserProfileAdmin)
When using admin page api key get correctly populated with a random value. However when saving the UserProfile it doesn't get saved, it is as if nothing was added. If I manually change a a single leter in the autogenerated key saving works correctly. It seems to me this is a problem with django detecting a change or something like this.
Any suggestions? Code worked in 1.4.