本文整理汇总了Python中person.models.Person.person_exists方法的典型用法代码示例。如果您正苦于以下问题:Python Person.person_exists方法的具体用法?Python Person.person_exists怎么用?Python Person.person_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类person.models.Person
的用法示例。
在下文中一共展示了Person.person_exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_person
# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import person_exists [as 别名]
def test_create_person(self):
forename = 'Mark'
surname = 'Rutte'
person = Person.objects.create(forename=forename, surname=surname)
self.assertEqual(Person.objects.count(), 1)
self.assertTrue(Person.person_exists(forename, surname))
person.update_info()
person.save()
self.assertEqual(person.wikidata_id, 'Q57792')
self.assertEqual(person.wikimedia_image_name.split('.')[1], 'jpg')
response = requests.get(person.wikimedia_image_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(person.birthdate, date(1967, 2, 14))
示例2: create_members
# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import person_exists [as 别名]
def create_members():
url = 'http://www.tweedekamer.nl/kamerleden/alle_kamerleden'
page = requests.get(url)
tree = lxml.html.fromstring(page.content)
parliament = get_or_create_tweede_kamer()
rows = tree.xpath("//tbody/tr")
for row in rows:
columns = row.xpath("td")
if len(columns) == 8:
surname = columns[0][0].text.split(',')[0]
print(surname)
prefix = columns[0][0].text.split('.')[-1].strip()
forename = columns[1][0].text
if Person.person_exists(forename, surname):
person = Person.objects.get(forename=forename, surname=surname)
else:
person = Person.objects.create(
forename=forename,
surname=surname,
surname_prefix=prefix,
)
party_name = columns[2][0].text
party = PoliticalParty.get_party(party_name)
# residence = columns[3][0].text
# age = columns[4][0][0].text
# sex = columns[5][0].text
# assert age is not None
# if sex == 'Man':
# sex = Member.MALE
# elif sex == 'Vrouw':
# sex = Member.FEMALE
party_member = PartyMember.objects.create(person=person, party=party)
parliament_member = ParliamentMember.objects.create(person=person, parliament=parliament)
print("new person: " + str(person))
print("new party member: " + str(party_member))
print("new parliament member: " + str(parliament_member))