老师,您好,下面这段代码,提示了如下的错误,找了好几遍都没发现原因,请问老师可以看一下吗?
import random
import string
from django.db import models
# Create your models here.
class Student(models.Model):
name = models.CharField(max_length=20)
age = models.IntegerField()
sex = models.IntegerField(choices=((1,'男'),(2,'女')),default=1)
card_no = models.CharField(max_length=18)
@classmethod
def insert_test_data(self,num):
#批量生产测试数据
def random_str(raw_ite,length):
#生产随机字符串
return "".join(random.choices(raw_ite,k=length))
obj_li = []
for _ in range(num):
obj_li.append(Student(
name = random_str(string.ascii_lowercase,random.randint(6,10)),
age = random.randint(18,26),
sex = random.choices([1,2]),
card_no=random_str(string.digits,18)
))
Student.objects.bulk_create(obj_li)
