def save(self): """ is sent to the class UserCode parameter of 20 and 8 for the number of codes and code length. """ bulk = Bulk(); values = []; self.cod = UserCode(20,8) self.codes = self.cod.generateCodes() for i in range(len(self.codes)):values.append(CreateCodes(franchisee = self.franchisee, code = self.codes[i], useFlagCode = False, dateUseFlag = None, dateCreateCode = datetime.now())) bulk.insertMany(CreateCodes,values)
class CreateCodes(models.Model): """ This model is based on the class 'BulkInsert' to create the 20 codes that are assigned to the franchisee or franchisee referenced and anchor with your franchisee level """ franchisee = models.ForeignKey('UserProfile', to_field='identification') code = models.CharField(max_length=20, editable=False, unique=True) useFlagCode = models.BooleanField(default=False, editable=False) dateUseFlag = models.DateTimeField(editable=False, blank=True, null=True) dateCreateCode = models.DateTimeField(auto_now_add=True, editable=False) def __unicode__(self): return "%s %s"%(self.franchisee, self.code) # saving codes generated for franchisees def save(self): """ is sent to the class UserCode parameter of 20 and 8 for the number of codes and code length. """ bulk = Bulk(); values = []; self.cod = UserCode(20,8) self.codes = self.cod.generateCodes() for i in range(len(self.codes)):values.append(CreateCodes(franchisee = self.franchisee, code = self.codes[i], useFlagCode = False, dateUseFlag = None, dateCreateCode = datetime.now())) bulk.insertMany(CreateCodes,values)