本文整理汇总了Python中models.Item.user方法的典型用法代码示例。如果您正苦于以下问题:Python Item.user方法的具体用法?Python Item.user怎么用?Python Item.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import user [as 别名]
def setUp(self):
super(ItemApiTest, self).setUp()
# Create a user.
self.username = 'test_user'
self.password = 'test_pass'
self.user = User.objects.create_user(self.username, '[email protected]', self.password)
# Create another user
self.username2 = 'test_user2'
self.password2 = 'test_pass2'
self.user2 = User.objects.create_user(self.username2, '[email protected]', self.password2)
item = Item()
item.name = "Test Item #1"
item.user = self.user
item.notes = "testing..."
item.save()
self.item = item
# Build a URI for the item
self.detail_uri = '/api/v1/todo/{0}/'.format(self.item.pk)
# ...as well as a URI to list all items
self.list_uri = '/api/v1/todo/'
# ...and URIs for each user
self.user_uri = '/api/v1/user/{0}/'.format(self.user.pk)
self.user2_uri = '/api/v1/user/{0}/'.format(self.user2.pk)
# The data we'll send on POST requests.
self.post_data = {
'user': self.user_uri,
'name': 'Test Item #2'
}
self.post_data2 = {
'user': self.user2_uri,
'name': 'Test Item #3'
}
# Expected test item JSON from server
self.test_item_json = {
'name': 'Test Item #1',
'created': str(self.item.created),
'notes': 'testing...',
'due': None,
'priority': 0,
'done': False,
'user': self.user_uri,
'id': str(self.item.pk),
'resource_uri': self.detail_uri
}
示例2: test_todo_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import user [as 别名]
def test_todo_item(self):
"""Tests the todo item model"""
# Does validation fail on an invalid item?
item = Item()
validatedSuccessfully = False
try:
item.full_clean()
except ValidationError:
validatedSuccessfully = True
self.assertEquals(validatedSuccessfully, True)
# Does validation pass on a valid item?
item.name = "test"
item.user = self.user
validatedSuccessfully = True
try:
item.full_clean()
except ValidationError:
validatedSuccessfully = False
self.assertEquals(validatedSuccessfully, True)