classAutoIncrementFields(models.Model): """ provide a unique ID for all models of code sign """ id = models.AutoField(primary_key=True) def__str__(self): returnstr(self.id)
classA(models.Model): """ example """ case_id = models.CharField(max_length=128, primary_key=True) # custom save func will cover this field defsave(self, *args, **kwargs): """ customize primary key like exp-1, exp-2... :param args: :param kwargs: :return: """ _ = AutoIncrementFields.objects.create() self.case_id = 'exp-' + str(_.id) returnsuper(A, self).save(*args, **kwargs)
classB(models.Model): """ example """ case_id = models.CharField(max_length=128, primary_key=True) # custom save func will cover this field defsave(self, *args, **kwargs): """ customize primary key like exp-1, exp-2... :param args: :param kwargs: :return: """ _ = AutoIncrementFields.objects.create() self.case_id = 'exp-' + str(_.id) returnsuper(B, self).save(*args, **kwargs)