There is a race condition here that can allow two netword being created at the same time to wind up with the same automatically generated v6prefix.  Changing the call that handles this to an after_save and changing this line to

max = id

will fix that race condition.