本文整理汇总了Python中models.Member.get方法的典型用法代码示例。如果您正苦于以下问题:Python Member.get方法的具体用法?Python Member.get怎么用?Python Member.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Member
的用法示例。
在下文中一共展示了Member.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testManyToManyOperation
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import get [as 别名]
def testManyToManyOperation(self):
team = Team.create(name="Houkago Tea Time")
for name in self.names:
team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3])
song1 = Song.create(name="Utauyo!! MIRACLE")
song2 = Song.create(name="Tenshi ni Fureta yo!")
for m in Member.all(): song1.members.append(m)
for m in Member.select(age=17): song2.members.append(m)
members = song1.members
self.assertEqual(members.count(), 5)
members = song2.members
self.assertEqual(members.count(), 4)
azusa = Member.get(first_name="Azusa")
songs = azusa.songs
self.assertEqual(songs.count(), 1)
self.assertEqual(songs[0].name, "Utauyo!! MIRACLE")
示例2: testCRUDObject
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import get [as 别名]
def testCRUDObject(self):
# Test for creating, reading, updating, deleteing
# Create team
name = "Houkago Tea Time"
team = Team.create(name=name)
self.assertEqual(str(team), "<Team '%s'>" % name)
self.assertEqual(team.id, 1)
# Create members
for idx, n in enumerate(self.names):
member = Member.create(band=team, first_name=n[0], last_name=n[1], part=n[2])
self.assertEqual(str(member), "<Member '%s'>" % n[3])
self.assertEqual(member.id, idx + 1)
# Get member with primary key
ritsu = Member.get(1)
self.assertEqual(str(ritsu), "<Member 'Ritsu Tainaka : Dr'>")
# Get team the member Ritsu belongs to is Houkago Tea Time
team = ritsu.band
self.assertEqual(str(team), "<Team 'Houkago Tea Time'>")
# Get members with iterator
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % self.names[idx][3])
# Yui changes instrument to castanets
macaron.bake() # Commit before changes
yui = Member.get(first_name="Yui", last_name="Hirasawa")
self.assert_(yui)
yui.part = "Castanets"
self.assertEqual(yui.part, "Castanets")
yui.save()
# Re-fetch Yui
member = Member.get(3)
self.assertEqual(member.part, "Castanets")
# Delete all members
self.assertEqual(team.members.count(), 4)
team.members.select(first_name="Ritsu").delete()
self.assertEqual(team.members.count(), 3)
team.members.delete()
self.assertEqual(team.members.count(), 0)
# Test for rollback
# Cancel the changes
macaron.rollback()
team = Team.get(1)
self.assertEqual(team.members.count(), 4)
# Add another member 'Sawako' as Gt1
member = Member.create(band=team, first_name="Sawako", last_name="Yamanaka", part="Gt1")
self.assertEqual(str(member), "<Member 'Sawako Yamanaka : Gt1'>")
# Re-fetch Sawako with index
sawako = team.members[4]
self.assertEqual(str(sawako), "<Member 'Sawako Yamanaka : Gt1'>")
# But, Sawako is not a member of the team
sawako.delete()
# Add another member Azusa through reverse relation of ManyToOne
team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2")
azu = Member.get(first_name="Azusa")
self.assertEqual(str(azu), "<Member 'Azusa Nakano : Gt2'>")
# Okay, Yui changes part to Gt1
yui = Member.get(first_name="Yui")
yui.part = "Gt1"
yui.save()
self.assertEqual(yui.part, "Gt1")
# At last, there are five menbers
nm = self.names[:]
nm[2] = ("Yui", "Hirasawa", "Gt1", "Yui Hirasawa : Gt1")
nm.append(("Azusa", "Nakano", "Gt2", "Azusa Nakano : Gt2"))
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % nm[idx][3])
# Foreign key constraint works on sqlite3 >= 3.6.19
ver = macaron.sqlite_version_info
if ver >= (3, 6, 19):
# Test for ON CASCADE
team = Team.get(1)
team.id = 2
team.save()
cnt = 0
for member in Member.all():
cnt += 1
self.assertEqual(member.band_id, 2)
self.assertEqual(cnt, Member.all().count())
# Test for ON DELETE
team.delete()
cnt = 0
for member in Member.all():
self.assertEqual(member.band, None)
cnt += 1
self.assertEqual(cnt, Member.all().count())
#.........这里部分代码省略.........