本文整理汇总了Python中models.Person.save方法的典型用法代码示例。如果您正苦于以下问题:Python Person.save方法的具体用法?Python Person.save怎么用?Python Person.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Person
的用法示例。
在下文中一共展示了Person.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def register(request):
if request.method == 'GET':
return httputils.render_html(request,'gobang/register.html', {})
else:
email = request.POST.get('email', default = None)
passwd = request.POST.get('passwd', default = None)
username = request.POST.get('username', default = None)
validation_code = request.POST.get('validation_code', default = None)
#check input not none
for item in (email, passwd,username,validation_code):
if item is None:
return render(request, 'gobang/register.html',{'error_msg':'input has none'})
#check validation code right
server_validation_code = validation_cache.get(email)
if server_validation_code is None or server_validation_code != validation_code:
return render(request, 'gobang/register.html',{'error_msg':'validation code not right'})
#insert db and use model to check input format right
added_person = Person(username=username,passwd=passwd,email=email)
try:
added_person.save()
except Exception as e:
#record exception
gobang_logger.error("insert db error, {0}".format(e))
return render(request, 'gobang/register.html',{'error_msg':str(e)})
#set sessions and redirect
request.session['login'] = True
request.session['pk'] = added_person.pk
request.session['username'] = added_person.username
return HttpResponseRedirect('/gobang/index')
示例2: populate_person
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def populate_person(root) :
"""
Finds instances of Person in root's tree and saves them to the database
@type root: Element
@param root: root of the ElementTree passed in to populate_models()
@rtype: N/A
@return: function does not return
"""
for person in root.findall("Person"):
temp_person = Person()
temp_person.person_ID = person.get("ID")
temp_person.name = person.get("Name")
if person.find("Kind") is not None :
temp_person.kind = person.find("Kind").text
if person.find("Location") is not None :
temp_person.location = person.find("Location").text
for crisis in person.iter("Crisis") :
temp_relations = Relations()
check = Relations.objects.filter(crisis_ID = crisis.get("ID"), person_ID = person.get("ID"))
if len(check) == 0:
temp_relations.populate(c_id = crisis.get("ID"), p_id = person.get("ID"))
temp_relations.save()
for org in person.iter("Org") :
temp_relations = Relations()
check = Relations.objects.filter(org_ID = org.get("ID"), person_ID = person.get("ID"))
if len(check) == 0:
temp_relations.populate(p_id = person.get("ID"), o_id = org.get("ID"))
temp_relations.save()
populate_common(person, person.get("ID"), temp_person)
temp_person.save()
示例3: doperson
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def doperson(request,username,method):
person=Person.objects.get(username=username)
if request.user.is_superuser:
if request.method=="GET":
result=1
elif request.method=="POST":
result=2
if method=='delete':#删除确认
person.delete()
elif method=='update':#更新表单
#update
personinfo_name = ['name', 'sex', 'age', 'adno','home','profession', 'education', 'disease_history', 'disease_age_h',
'disease_current','disease_age_c', 'used_drugs', 'using_drugs']
try:
person = Person.objects.get(username=username)
except Person.DoesNotExist:
person = Person(username=username)
for key in personinfo_name:
setattr(person,key,request.POST.get(key,''))
person.save()
else:#显示查看界面
result=0
else:#无权操作
result=-1
return render_to_response('person.html', locals())
示例4: merge_people
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def merge_people(elem):
"""
Parses data from "<Person />" tags
Checks if entry already exists
If so, do a merge
else, import the model data
Saves model to mysql database
"""
for p in elem :
person_filter_obj = Person.objects.filter(wcdb_id = p.get('ID'))
if (len(person_filter_obj) != 0):
person = person_filter_obj[0] #if person exists, use it
person.name = p.get('Name')
else: #else make a new one
person = Person(name = p.get('Name'), wcdb_id = p.get('ID'))
kind = p.find('Kind')
location = p.find('Location')
common = p.find('Common')
if (kind != None):
person.kind = kind.text
if (location != None):
person.location = location.text
if (common != None):
merge_common(common, person)
person.save()
示例5: create_player
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def create_player(first, last):
person = Person(first_name=first, last_name=last)
person.save()
player = Player(person=person)
player.save()
return player
示例6: test_setter
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def test_setter(self):
# The "full_name" property hasn't provided a "set" method.
self.assertRaises(AttributeError, setattr, self.a, 'full_name', 'Paul McCartney')
# But "full_name_2" has, and it can be used to initialise the class.
a2 = Person(full_name_2 = 'Paul McCartney')
a2.save()
self.assertEqual(a2.first_name, 'Paul')
示例7: save
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def save(self):
password = self.cleaned_data.pop('password1')
self.cleaned_data.pop('password2')
person = Person(**self.cleaned_data)
person.set_password(password)
person.save()
return person
示例8: setUp
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def setUp(self):
Redis().flushall()
p1 = Person(name='Test User 1', ssn='123456789')
p1.save()
pn1 = PhoneNumber(person=p1, label='Test 1', phone_number='5558675309')
pn1.save()
from django import db
db.reset_queries()
示例9: get_image_info
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def get_image_info(self, uid, name):
post_data = {'api_key': self.api_key(),
'api_secret': self.api_secret(),
'img_uid': uid}
r = requests.post(self.base_url() + 'GetImageInfo', post_data)
json_obj = json.loads(r.content)
p = Person(uid=json_obj['faces'][0]['uid'], name=name)
p.save()
return r
示例10: magic
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def magic(request):
p1 = Person(login = "picrin", hashedPassword = "similar")
p1.save()
k1 = Tokena(value = "please come in", active = True, belongs_to = p1, created=datetime.datetime.utcnow())
k1.save()
k2 = Tokena(value = "you're not welcome", active = False, belongs_to = p1, created=datetime.datetime.utcnow())
k2.save()
print k1
print k2
return HttpResponse("nice", RequestContext(request))
示例11: addperson
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def addperson():
meeting = get_meeting()
names = [x.name for x in meeting.people]
if request.method == 'POST':
name = request.form['username']
if name not in names:
person = Person(name=name)
person.save()
meeting.people.append(person)
meeting.save()
return redirect('/status/%s' % name)
示例12: setUp
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def setUp(self):
# create classifcation
self.classification = create_classification('Men\'s Open')
# create an Address and a Field
self.address = Address(street='ABC Street')
self.address.save()
self.field = Field(name='Field 1', address=self.address)
self.field.save()
# create teams
self.team_1 = create_team('Team 1', self.classification)
self.team_2 = create_team('Team 2', self.classification)
# create some players
self.player_1 = create_player('One', '1')
self.player_2 = create_player('Two', '2')
self.player_3 = create_player('Three', '3')
# assign the players
self.playfor_1 = PlayFor(player=self.player_1, team=self.team_1, from_date=datetime.date.today())
self.playfor_1.save()
self.playfor_2 = PlayFor(player=self.player_2, team=self.team_1, from_date=datetime.date.today())
self.playfor_2.save()
self.playfor_3 = PlayFor(player=self.player_3, team=self.team_1, from_date=datetime.date.today())
self.playfor_3.save()
# create referee
person = Person(first_name='Ref', last_name='Ref')
person.save()
self.referee = Referee(person=person)
self.referee.save()
# create two seasons
self.season_1 = create_season(self.classification, 'Division 1', '2014-2015', datetime.date.today(), datetime.date.today())
self.season_2 = create_season(self.classification, 'Division 2', '2015-2016', datetime.date.today(), datetime.date.today())
# create some games
self.matchday_season_1 = Matchday(season=self.season_1, label='1', date=datetime.date.today())
self.matchday_season_1.save()
self.game_season_1 = Game(matchday=self.matchday_season_1, date=datetime.date.today(),
away_team=self.team_1, home_team=self.team_2, referee=self.referee,
played=True, field=self.field)
self.game_season_1.save()
self.matchday_season_2 = Matchday(season=self.season_2, label='2', date=datetime.date.today())
self.matchday_season_2.save()
self.game_season_2 = Game(matchday=self.matchday_season_2, date=datetime.date.today(),
away_team=self.team_1, home_team=self.team_1, referee=self.referee,
played=True, field=self.field)
self.game_season_2.save()
示例13: register
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
person = Person()
person.name = form.cleaned_data['name']
person.email = form.cleaned_data['email']
person.save()
return HttpResponseRedirect('../list/')
else:
form = RegistrationForm()
return render(request, '../templates/register.html', {'form': form})
示例14: test_create
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def test_create(self):
from django.conf import settings
from django import db
settings.DEBUG = True
p2 = Person(name='Test User 2', ssn='123456788')
p2.save()
self.assertEqual(len(db.connection.queries), 1)
p2_r = Person.objects.get(pk=p2.pk)
self.assertEqual(p2, p2_r)
self.assertEqual(len(db.connection.queries), 1)
示例15: save
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import save [as 别名]
def save(self):
username = self.cleaned_data['username']
password = self.cleaned_data['password']
email = self.cleaned_data['email']
user = User.objects.create_user(username = username, email = email, password = password)
user.save()
person = Person(user = user, verified = True, email = email, name = username)
person.save()
self.person = person
activate = Activation(key = str(uuid.uuid4()), person = person)
activate.save()
self.activate = activate
self.success = True
return (self.person, self.activate)