def add_person(request): # person = Person.objects.create(p_name='WangGang', p_age=20, p_sex=False) # person = Person(p_age=28) person = Person.create('Jack') person.save() return HttpResponse('创建成功!')
def add_person(request): # person = Person.objects.create(p_name='sunck', p_age=16, p_sex=True) # person = Person(p_name='hjl', p_age=18, p_sex=True, p_hobby='sleeping') person = Person.create(p_name='jack') person.save() return HttpResponse('加入一个用户成功')
def add_person(request): # person = Person.objects.create(p_name='mm',p_age=13,p_sex=True) person = Person.create('Jack') person.save() return HttpResponse("sunck")
def add_person(request): # person = Person.objects.create(p_name="Sunck", p_age=15, p_sex=True) # 是"" ,不是 None Null, 不能重写 __init__ ,可以通过其他手段,实现属性自定义赋值 person = Person(p_age=28) person = Person.create('Jack') person.save() return HttpResponse("Jack 创建成功")
def add_person(request): """ ##一次性新增一个数据库字段的三种方式: 1.先实例化对象,然后依次或者随意给类属性赋值(没有赋值的属性,默认保存为blank),最后执行对象的save方法; 2.直接用类的方法,但create方法内部需要填写所有字段; Person.objects.create() 3.将类实例化的过程中,直接在类中赋值属性(赋值所有属性),然后用实例化对象的save方法:peo = Person() peo.save() 4.在模型中(models.py中Person模型)创造了一个自定义的create类方法,然后用实例化后的对象执行save方法:Person.create() peo.save() """ flag = random.randrange(10000) # 方法一: # peo = Person() # peo.p_age = flag # peo.save() # 方法二: # #Person.objects.create(p_name="bob %d" % flag, p_age=15, p_sex=1) # 方法三: # ##peo = Person(p_name="Bob %d" % flag, p_age=15, p_sex=1) # ##peo.save() # 方法四: peo = Person.create(p_name="wurui") peo.save() return HttpResponse("add one")
def add_person(request): # person = Person.objects.create(p_name="jack", p_age=30, p_sex=False) # person = Person(p_name='Rose', p_age=20, p_sex=False) person = Person.create('Sharon') person.save() return HttpResponse("Jack create success")
def add_person(request): # person = Person.objects.create(p_name='sunck', p_age=15, p_sex=True) # person = Person(p_age=28) person = Person.create('Jack') person.save() return HttpResponse('Sunck succeed')
def add_person(request): # person = Person.objects.create(p_name="Sunck1", p_age=15, p_sex=True) person = Person.create('Jack') person.save() return HttpResponse("Sunck1创建成功")